Datetime in ESQL/C
Posted in 1999
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL, Third-Party Tools & Monitoring
I am writing an ESQL/C program where I want to compare 2 datetime fields. Is there a way to do a comparison on 2 datetime fields? I could convert the dates to a float and test, but would rather not if there is a better way. I am using version 7.23.UC1 ESQL/C and 7.30.UC2 Online Engine. Here is a sample of what I am trying to do. EXEC SQL BEGIN DECLARE SECTION; datetime year to fraction(3) date1; datetime year to fraction(3) date2; EXEC SQL END DECLARE SECTION; main() { dtcvasc("1999-01-31 23:59:59.345", &date1); dtcvasc("1999-02-01 00:00:00.000", &date2); if (date1 < date2) { do something... } } Thanks for any advice on this, Jenny Brausch Hewlett-Packard Corvallis, OR
Jenny Brausch wrote: > > I am writing an ESQL/C program where I want to compare 2 datetime fields. > Is there a way to do a comparison on 2 datetime fields? I could convert > the dates to a float and test, but would rather not if there is a > better way. I am using version 7.23.UC1 ESQL/C and 7.30.UC2 Online Engine. > Here is a sample of what I am trying to do. > > EXEC SQL BEGIN DECLARE SECTION; > datetime year to fraction(3) date1; > datetime year to fraction(3) date2; > EXEC SQL END DECLARE SECTION; > > main() { > > dtcvasc("1999-01-31 23:59:59.345", &date1); > dtcvasc("1999-02-01 00:00:00.000", &date2); > > if (date1 < date2) { > > do something... > > } > } > > Thanks for any advice on this, There are couple of things you could do. One is to check the manuals to see whether the datetime comparison routines are documented. If so, you can use them. Alternatively, you can write your own code to do the comparison. The compare should probably fail if the qualifiers of the two types are not compatible (identical? you probably want to be able to compare an X TO FRACTION(3) with an X TO FRACTION(4), and it isn't hard to do. Assuming the qualifiers are sufficiently similar, you can then compare the decimal portions of the datetimes with the documented deccmp() function. -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v0.60 -- see http://www.perl.com/CPAN #include <disclaimer.h>