Translating with DrWatson… this can take a few seconds the first time.
This is a genuine, complex translation. DrWatson protects commands, error codes, and log output while naturally translating the surrounding text. It’s translated once and saved.
A developer writing a C UDR asked how to extract year/month/day/hour as integers from an Informix mi_datetime value. Suggestions were to use mi_datetime_to_string() and parse the result (e.g. with strtol), or to work directly with the internal format, which the DataBlade API docs describe as a qualifier plus a decimal value of the form yyyymmddhhmmss.fff whose digits can be inspected. Jonathan Leffler added that ESQL/C routines exist: convert the datetime to a date and use the date-component functions, though time parts take more effort. No single ready-made conversion call was identified.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Hi Donny,
I have seen that function. For actual canculation i need the year, month day
and hour in integers and not string values.
Assuming that mi_datetime is a structure must no be so hard to calculate
this values to integer values. I assume that deep below in
mi_datetime_to_string there will also be a converion to integers/longs and
then print this in a string.
Bart
Bart Huls wrote:
> Hi Donny,
>
> I have seen that function. For actual canculation i need the year, month day
> and hour in integers and not string values.
Probably easiest to cut it up with strtol(3)
> Assuming that mi_datetime is a structure must no be so hard to calculate
> this values to integer values. I assume that deep below in
> mi_datetime_to_string there will also be a converion to integers/longs and
> then print this in a string.
It's stored as a decimal, something like "yyyymmddhhmmss.fff", depending
on the qualifiers.
On Wed, 2006-03-29 at 07:14, Bart Huls wrote:
> Hi Donny,
>
> I have seen that function. For actual canculation i need the year, month day
> and hour in integers and not string values.
> Assuming that mi_datetime is a structure must no be so hard to calculate
> this values to integer values. I assume that deep below in
> mi_datetime_to_string there will also be a converion to integers/longs and
> then print this in a string.
The internal format of mi_datetime is described in
http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.dapip.doc/dapip105.htm
This tells you that a datetime value has a qualifier (which indicates
the precision such as YEAR to SECOND) and a value that is given as a
decimal number. You should be able to inspect the appropriate digits of
this decimal number to retrieve the numeric values for the constituent
parts of the datetime.
Alternatively, you could parse the string you get from
mi_datetime_to_string.
Hope this helps,
Carsten.
Bart Huls wrote:
> Am I reading it correctly that informix has no normal datetime routines as
> you would expect in C or other language.....
No. There are a number of routines that could be used, documented in
the ESQL/C Programmers' Reference Manual. The simplest way to get YEAR,
MONTH or DAY is to convert the datetime to a date, then invoke the
routines to extract the bits and pieces. If you're after hours, minutes
and seconds, then you have to work a bit harder.
--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2005.02 -- http://dbi.perl.org/
Your privacy choices
We use strictly necessary cookies to make this site work. With your
consent we’d also use optional cookies for analytics and marketing. You can accept all,
reject all, or choose. Read our Cookie Policy.