[comp.lang.c] CORRECTION: Date to DOW Conversion

markt@tse.uucp (Mark Turner) (06/25/91)

More on the date to day-of-week conversion. From msb@sq.com:

>> Well, I'm afraid it is embarassingly obvious.  Check your manual for the
>> <time.h> functions.  You take your date and plug values into a variable
>> of type 'struct tm'.  Once you have that, you use mktime() to convert
>> it to a time_t, simultaneously filling in the missing fields ...
>
>I'm afraid this is not quite right.  You must fill in the *time*
>as well as the *date* members of the struct.  If you leave them
>uninitialized they may contain garbage values and effectively change
>the date.
>
>For instance, suppose the tm_hour member was uninitialized and
>happened to contain the value 411.  411 = 17*24 + 3, so if the
>date you thought you were asking about was July 1, then mktime()
>would provide information about July 18 (17 days later) at 3:00 am
>-- that is, assuming that tm_min and tm_sec, at least, were 0.
>And therefore the day of the week would be 3 days off.
>
>For your purposes it suffices to assign 0 to the tm_hour, tm_min,
>and tm_sec members.
>

By the way, thanks to all those who sent me algorithms on how to perform
a date to day-of-week conversion in the absence of mktime(). I haven't had the
time to respond to each of you individually, but your efforts are appreciated.

--------------------------------------------------------------------------------
Regards,                        
Mark Turner                     
UUCP:  markt@tse.UUCP