datetime Subtraction
Posted in 1994
Topics: General Discussion
I'm trying to successful subtract two datetime fields and obtain the resulting interval value. I've found an example program that works for datetimes of day to second, but I need something that will work for 2 datetimes of year to second and then give me a result in the form of hour to second. The code I am using is as follows: #include <stdio.h> $include sqlca; $include datetime; #include <decimal.h> main() { $datetime year to second dt1, dt2; char cf3[40]; int x; dt1.dt_qual = TU_DTENCODE(TU_YEAR,TU_SECOND); dt2.dt_qual = TU_DTENCODE(TU_YEAR,TU_SECOND); if (x=dtcvasc("1994-01-21 10:30:03",&dt1)) { printf("Conversion error: %d\\n",x); exit(-1); } if (x=dtcvasc("1994-01-20 10:30:03",&dt2)) { printf("Conversion error: %d\\n",x); exit(-1); } printf("Values used for calculations are:\\n"); dttoasc(&dt1,cf3); printf("\\tdt1 = %s\\n",cf3); dttoasc(&dt2,cf3); printf("\\tdt2 = %s\\n",cf3); { $interval hour(3) to second rinv; char obuff[32]; rinv.in_qual = TU_IENCODE(3,TU_HOUR,TU_SECOND); rdtsub(&dt1.dt_dec,dt1.dt_qual,&dt2.dt_dec,dt2.dt_qual, &rinv.in_dec,rinv.in_qual); intoasc(&rinv,obuff); printf("result of d1 - d2 = %s\\n",obuff); } } The output from this program is: Values used for calculations are: dt1 = 1994-01-21 10:30:03 dt2 = 1994-01-20 10:30:03 result of d1 - d2 = 0:00:01 However, the "result of" line should show a result of 24:00:00 instead of 0:00:01. What is going on here? What am I doing wrong??? Any help is greatly appreciated... Thanks, Chris Hushour ------------------------------------------------------------------------------ Chris Hushour Internet: cwh@evolving.com Evolving Systems Incorporated Englewood, Colorado ------------------------------------------------------------------------------ -- ------------------------------------------------------------------------------ Chris Hushour Internet: cwh@evolving.com Evolving Systems Incorporated Englewood, Colorado