Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 653
Ole Avatar asked Dec 04 '08 17:12

Ole


2 Answers

Since there is not an exact solution for the topic:

=> SELECT date_part('epoch', INTERVAL '1 day 01:30:00') * INTERVAL '1 second' hours;   hours -----------  25:30:00 (1 row) 

Source: Documentation

like image 142
neshkeev Avatar answered Oct 07 '22 16:10

neshkeev


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.

like image 29
mat Avatar answered Oct 07 '22 14:10

mat