John Wick
John Wick

Reputation: 29

PostgreSQL get time difference between two text fields

I have two fields in table like

Time1(varchar)     Time2(varchar)
13:01:15           14:02:06

How do I get the time difference between these two fields?

Upvotes: 0

Views: 214

Answers (1)

user330315
user330315

Reputation:

You can cast the values to a proper time value, then simply subtract them:

'14:02:06'::time - '13:01:15'::time 

or

time_2::time - time_1::time

The result is an interval

Upvotes: 1

Related Questions