How to convert an interval like "1 day 01:30:00" into "25:30:00"?

Ole picture Ole · Dec 4, 2008 · Viewed 48k times · Source

I need to add some intervals and use the result in Excel.

Since

sum(time.endtime-time.starttime)

returns the interval as "1 day 01:30:00" and this format breaks my Excel sheet, I thought it'd be nice to have the output like "25:30:00" but found no way to do it in the PostgreSQL documentation.

Can anyone here help me out?

Answer

mat picture mat · Dec 4, 2008

The only thing I can come with (beside parsing the number of days and adding 24 to the hours every time) is :

mat=> select date_part('epoch', '01 day 1:30:00'::interval);
 date_part 
-----------
     91800
(1 row)

It will give you the number of seconds, which may be ok for excel.