Re: DBTIME and time date types
Posted in 1998
apatnaik@aircom.com wrote: > > hello, > > I am being passed in a character string which contains a > date/time in the following format: > YYYY-MM-DD HH:MM:SS > > ex: 1998-05-18 09:05:00 > > I need to convert it such that it looks like the below: > Mon May 18 09:05:00 EDT 1998 <-- output like that of unix time() > > I would like to know if there is an easy way to do the > above. I am able to obtain the above format except > for the day of the week and the time zone by making > calls to dtcvasc() to convert to a datetime, and then > using dttofmtasc() with formatting. Is there a general > utility either in Informix or in C that can allow me to > print the day of the week?? Get my submission to the IIUG Software Repository named datelib_ak. It contains a function, getdate, which will accept text date input in freeform and returns a struct timeval which contains a UNIX time_t and number of microseconds since the last second. You can then pass the time_t component to localtime() to get a struct tm which, in turn, can be passed to asctime to get the string format you desire. Getdate() accepts VERY loose freeform dates anything from the Informix datetime output format (ie ANSI dates) to something like "3 days 4 hours 12 minutes after yesterday" are accepted and converted to reasonable results. The example given returns "Fri Jul 3 14:28:28 1998" at 10:16:28 today, July 1, 1998 localtime using the test main() provided. Art S. Kagel