Re: DBTIME and time date types
Posted in 1998
On Tue, 30 Jun 1998 apatnaik@aircom.com wrote: > 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. No, not really. > 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?? I'd probably convert the string into a datetime, then convert the datetime into the number of seconds since 1970-01-01 00:00:00, and then use localtime(3) or gmtime(3) to convert to a struct tm, and then, finally, strftime(3) to convert and format the string. That's a long-winded sequence. Alternatively, if strptime() is available on your platform, use strptime(3) to do the input conversion direct to struct tm format. strftime() has both %Z for the time zone name and %a for abbreviated day name, as you require. I thought dttofmtasc() probably did too, but I see it does not. Remember that the DATETIME value does not have a timezone explicitly associated with it, which makes life kinda hard. Yours, Jonathan Leffler (jleffler@informix.com) #include <witticism.h> Guardian of DBD::Informix -- see http://www.perl.com/CPAN