April 27th, 2004, 10:35 AM
Convert string to time_t
Let me try to explain my problem... I´m reading rows from a database, using a time_t parameter to tell the initial time (only rows with time greater than this parameter will be returned). ok!
I need to save (in a file) the last time_t parameter used in the request. I´m saving this parameter like it is (a long int, for example 1083075041). But...
In this format, it´s hard to users to change this information, so I want to save this time_t parameter in the format return by c_time function (a string).
Is there any way, after doing this, to convert this string back to time_t? :confused:
Since now, thanks a lot!!!! :)
April 27th, 2004, 10:38 AM
Take the parts of the date, stick them in a tm struct, then pull it back out as a time_t. Time consuming, but to my knowledge there is no library out there (at least not standard) that will help you.
April 27th, 2004, 10:41 AM
I was affraid of with :)
April 27th, 2004, 12:42 PM
it's really not all that difficult as long as you know the ascii format. Once you put everything in the struct tm, just call mktime(), which will return the time_t. Make sure you pre-initialize the struct tm to all binary zeros before doing anything with it because, if you don't, mktime() may not work correctly. there are some fields you don't have to worry about, such as julian day or day-or-week. Just complete year, month, day, hour, minute and second.
April 27th, 2004, 02:32 PM