PlanetK
PlanetK

Reputation: 1

How to calculate the timestamp for the end of a call when given the timestamp for the start of the call and the duration of the call in hh:mi:ss?

I have a field labeled Call_Timestamp which is the date/time at which a call begins. I then have a field labeled Call_Time which is the duration of the call in hh:mi:ss. How would I add the Call_Time to the Call_Timestamp to get a timestamp for the end of the call? Thank you!

Upvotes: 0

Views: 184

Answers (1)

MT0
MT0

Reputation: 168361

You can use:

SELECT call_timestamp + ( TO_TIMESTAMP( call_time, 'HH24:MI:SS' )
                        - TO_TIMESTAMP( '00:00:00', 'HH24:MI:SS' ) )
         AS call_end_timestamp
FROM   your_table

or:

SELECT call_timestamp + TO_DSINTERVAL( '0 ' || call_time )
         AS call_end_timestamp
FROM   your_table;

Even better would be to store the CALL_TIME field as an INTERVAL DAY TO SECOND type then you can just add the two:

SELECT call_timestamp + call_time AS call_end_timestamp
FROM   your_table

Upvotes: 1

Related Questions