Thomas Lockhart <lockhart@alumni.caltech.edu> writes:
>> Seems like you could just skip step 3 and call localtime() with fields
>> indicating midnight of the specified date. Then use the complete
>> localtime result (don't discard any fields) and you should be OK, no?
> Pretty sure this won't work, since the complete localtime result will
> not be local midnight, which is the expected result.
Actually, now that I go back and reread the man pages, the correct
recipe is
* fill a struct tm with y/m/d, h = m = s = 0, isdst = -1
* call mktime() to produce a time_t
* either use the updated struct tm (mktime() side effect),
or convert the time_t directly to timestamp.
mktime() is an ANSI C requirement, so even though it's not as old as
localtime(), it's probably safe enough.
regards, tom lane