Obtain a result from the diference between 2 timestamps

Database

Obtain a result from the diference between 2 timestamps

Hi everybody,

I want to obtain the diference between to timestamp fields

Example:

Timestamp field 1: '12:49:00'

Timestamp Field 2: '12:51:15'

Result must be: '00:02:15' (the time elapsed between the field1 and field2)

How can obtain this result?

Thanks in advance for your support.

Tags (1)
2 REPLIES
Enthusiast

Re: Obtain a result from the diference between 2 timestamps

You can use the following query:

SEL TIME '12:51:00' -  INTERVAL  '12:49:15' HOUR TO SECOND;
Khurram
Junior Contributor

Re: Obtain a result from the diference between 2 timestamps

When you substract 2 timestamps the result is an INTERVAL:

select (timestamp2 - timestamp1) day(4) to second

Caution: this will fail if the difference is >= 10000 days (27 years)

Dieter