views:

546

answers:

1

Say I have an interval like

4 days 10:00:00

in postgres. How do I convert that to a number of hours (106 in this case?) Is there a function or should I bite the bullet and do something like

extract(days, my_interval) * 24 + extract(hours, my_interval)
+5  A: 

Probably the easiest way is:

SELECT EXTRACT(epoch FROM my_interval)/3600
Magnus Hagander
And maybe floor or cast the result to integer if the interval contains minutes and/or seconds
rasjani
Extract epoch? Oh my, that wouldn't have crossed my mind in a million years.
agnul