SQL: Duration between two datetime values in seconds
Posted in 2000
Topics: General Discussion
I simply what to calculate the difference between two datetime values in seconds. I.e. dtactivation = "1999-30-11 00:00:00" dttermination ="1999-30-11 00:02:15" The duration in seconds is 135 seconds. As there is no function like 'duration unit seconds' I tried the following. select (extend (dttermination, minute to minute)- dtactivation)*60 from TABLE where idTABLE = 1; The result is correctly 120 but as an Interval value select (extend (dttermination, second to second)- dtactivation) from TABLE where idTABLE = 1; The result is correctly 15; The final statement select (extend (dttermination, minute to minute)- dtactivation)*60+(extend (dttermination, second to second)- dtactivation) from TABLE where idTABLE = 1; does not show 135. Any suggestions? Sent via Deja.com http://www.deja.com/ Before you buy.
Oliver Thinnes wrote: > I simply what to calculate the difference between two datetime values in > seconds. > I.e. dtactivation = "1999-30-11 00:00:00" > dttermination ="1999-30-11 00:02:15" > The duration in seconds is 135 seconds. > > As there is no function like 'duration unit seconds' I tried the > following. No, but there's a datatype INTERVAL SECOND TO SECOND, which you can use for the number of seconds between two datetimes. I'm really rusty at this, but it would be something like: select extend (dttermination - dtactivation, second to second) from table June -- june_t@hotmail.com Back from the dead, resuscitated by Godiva chocolates... Please do not send Informix questions to this account. I would add 'Please do not send spam to this account' but I suppose I would be wasting my bits.