Ranier Cordeiro
Ranier Cordeiro

Reputation: 13

Time interval difference between dates in Redshift

I need to analyze the time interval difference from two dates in Amazon-Redshift, for example:

'2021-10-13 14:37:00' - '2021-10-13 12:00:00' = '02:37:00'

or in case the days is different:

'2021-10-13 14:37:00' - '2021-10-12 12:00:00' = '26:37:00'

I figured out only datediff() function. This function only return part from what I want.

So, is there a way better to return the result that I need?

Upvotes: 1

Views: 1346

Answers (1)

The Impaler
The Impaler

Reputation: 48770

Subtract them using - to get an INTERVAL. Then, you can just format the interval according to your needs. For example:

select to_char(timestamp '2021-10-13 14:37:00' - 
               timestamp '2021-10-13 12:00:00', 'HH:MI:SS')

Result:

02:37:00

Upvotes: 2

Related Questions