Problem with datetime in Esql/C program
Posted in 2000
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
I'm getting a strange error occasionally with datetime values in an Esql/C program. The datetime fields in my record structures are defined as datetime year to second. For example: $struct SATREC { datetime year to second adate; datetime year to second cdate; }; $struct SATREC atran; $struct SATREC btran; In my Esql/C program, I convert an ascii string received in a satellite packet to a datetime variable: dtcvasc(&datebuf[0],&atran.adate); (Where datebuf is stored in datetime format, e.g., "2000-06-30 23:48:58") I frequently use deccopy to copy datetime values between two program datetime variables since there does not appear to be an Informix routine to do this, e.g., deccopy(&atran.adate.dt_dec,&btran.cdate.dt_dec); Is there a better way to copy a datetime value? In the program, I frequently need to compare the number of seconds between datetime program variables. Since Informix does not appear to have a utility which allows me to do this, I wrote a C routine which returns the number of seconds between two values which have been passed to the program. The values are passed as character arrays in the same format as the Informix datetime year to second character array - dec_t.dec_dgts[7]. Sample character array: 20 0 6 30 12 14 06 = "2000-06-30 12:14:06" Offset 0 1 2 3 4 5 6 The program works fine, assuming the values passed to it are correct. Occasionally, when comparing the system date to the satellite date, my program generates an error that the satellite packet is more recent than the system date, which should not happen. I put some error checking in which dumps the value of dt_dec.dec_dgts when this happens. When it happened yesterday, the error checking showed that the values contained in the btran.cdate.dt_dec.dec_dgts array were: 20 0 7 5 13 20 28 However, the date returned from dttoasc(&btran.cdate) was "2000-07-05 13:20:00 Just prior to this, the program had done a deccopy from atran.adate to btran.cdate. At first I suspected the deccopy had somehow corrupted the array, but, if so, the dttoasc should have returned "2000-07-05 13:20:28" Any idea where the "28" is coming from? And why dttoasc is not picking this up? I'm running SE 5.10.UC2 and ESQL/C 5.10.UC2