Posted by Huxly on 16:59:00 10-17-2001
I understand the ctime() function and
have no trouble getting the current date
and time. But how do I compare and
input date for validity? Suppose a non
existant date was entered, like February 31,
is there a function that will spot the
bad date?
My program uses an array of strings, thus:
Yesterday
Today
Tomorrow
Today + 2
I need a valid date to match each of them.
"Today" is no problem. But getting a valid
data for the others could be a problem
if I have no way to stop the illegal date.
I know Linux has the information I need.
The cal command prints out any year or
month of any year, past or present. But how
do I get at that information to assign or
validate dates?
Any information would be appreciated.
Posted by dnathief on 15:23:00 01-09-2002
I'm fairly sure you'd use strftime(), but don't quote me
Posted by KaGez on 12:56:00 01-10-2002
maybe you can find something in the source of those commands like that thing you've mantioned. Also a good thing would be to check out the GTK calendar widget. It's quite complete, and I think that it also has the necessary error-check functions it needs. Maybe also the evolution source will help you out.
Other things to check would be the GNU stuff like "date" or something. maybe they also contain some informations!
[addsig]
Posted by seunosewa on 18:14:00 03-31-2002
It sure would be fun to actually implement the funcion you just decribed, in C++.
[[C may not be that much fun, though ]]
Posted by KaGez on 03:07:00 04-01-2002
I think that there already is such a function, in some library.
Btw, you could use PHP, because in PHP that stuff is really easy
_________________
cheers
KaGez
[ This Message was edited by: KaGez on 2002-04-01 03:08 ]
Posted by Yjo on 21:28:00 04-06-2002
not too difficult, convert the current time to a long (UTC, number of seconds since Jan 1 1970) and add/subtract 60*60*24 for each day from/before today, and then convert bact to struct tm, so that you can extract the month, year etc. (tm_mon, tm_mday...)
the routine will work out the day+month based on your computer's calendar setup.
Code:
struct tm *relativeday(short howmany)
return gmtime(time(NULL)+howmany*86400);