ESQL/C: Converting DATE to DATETIME
Posted in 2006
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
Dear Informixers, datetime issues keep haunting me :-( What is the most economic way to convert an ESQL/C date variable to a datetime variable? I have a date column in a database table that I need to use in datetime calculations. In this case, I need datetime year to minute. I know that I can just fetch the contents of the date column into a suitable datetime host variable and have Informix convert it on the fly. But when I have a date (= long) host variable that I need to convert into datetime year to minute? I have done it by printing the date variable into a suitable string (using rfmtdate()), concatenating " 00:00" to that string for the time portion, and then reading the result into a datetime variable using the dtcvasc() function. This works, but feels kind of clumsy. Is there a better way to do it? Regards, Richard
Richard Spitz wrote: > Dear Informixers, > > datetime issues keep haunting me :-( > > What is the most economic way to convert an ESQL/C date variable > to a datetime variable? > > I have a date column in a database table that I need to use in > datetime calculations. In this case, I need datetime year to minute. > > I know that I can just fetch the contents of the date column into > a suitable datetime host variable and have Informix convert it > on the fly. But when I have a date (= long) host variable that > I need to convert into datetime year to minute? > > I have done it by printing the date variable into a suitable string > (using rfmtdate()), concatenating " 00:00" to that string for the > time portion, and then reading the result into a datetime variable > using the dtcvasc() function. This works, but feels kind of clumsy. > > Is there a better way to do it? Get my "C" date/datetime manipulation library (datelib_ak) from the IIUG Repository. You'll find functions idatetoMydate4() a Mydate4_t is the date component of a My_Datetime_t which you can pass into the function mydttoidt() which will produce an Informix dtime_t structure with the desired precision. Art S. Kagel
assume you are on >= V9.XX
dbaccess stores7 <<!
select order_date :: datetime year to minute
from orders
!
Superboer.
Richard Spitz schreef:
> Dear Informixers,
>
> datetime issues keep haunting me :-(
>
> What is the most economic way to convert an ESQL/C date variable
> to a datetime variable?
>
> I have a date column in a database table that I need to use in
> datetime calculations. In this case, I need datetime year to minute.
>
> I know that I can just fetch the contents of the date column into
> a suitable datetime host variable and have Informix convert it
> on the fly. But when I have a date (= long) host variable that
> I need to convert into datetime year to minute?
>
> I have done it by printing the date variable into a suitable string
> (using rfmtdate()), concatenating " 00:00" to that string for the
> time portion, and then reading the result into a datetime variable
> using the dtcvasc() function. This works, but feels kind of clumsy.
>
> Is there a better way to do it?
>
> Regards, Richard