formatting intervals with to_char

From: Graham Davis <gdavis(at)refractions(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: formatting intervals with to_char
Date: 2006-10-03 23:03:30
Message-ID: 4522EC42.1080500@refractions.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

Hi,

I'm trying to format the output of a time interval so that it displays
as HH:MM:SS no matter how many days it spans. So for instance, an
interval of 2 days 4 hours and 0 minutes would look something like
"52:00:00". The documentation for to_char states that:

"|to_char(interval)| formats HH and HH12 as hours in a single day, while
HH24 can output hours exceeding a single day, e.g. >24."

However I can not get it to work with time intervals that span more than
1 day. For instance, the following query returns this time interval:

Query:
select ('2006-09-15T23:59:00'::timestamp - '2006-09-01
09:30:41'::timestamp);

Result:
14 days 14:28:19

But when I run to_char on this with HH24, it doesn't take into effect
the number of days:

Query:
select to_char(('2006-09-15T23:59:00'::timestamp - '2006-09-01
09:30:41'::timestamp), 'HH24:MI:SS');

Result:
14:28:19

It just gives me the offset of hours, min, seconds on that 14th day.
The result I'm looking for is: 350:28:19

What am I doing wrong, or how can I get this desired output? Thanks,

--
Graham Davis
Refractions Research Inc.
gdavis(at)refractions(dot)net

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2006-10-03 23:29:41 cvsweb.cgi missing colors
Previous Message Tom Lane 2006-10-03 22:54:15 Re: buildfarm failures in ECPG-Check

Browse pgsql-sql by date

  From Date Subject
Next Message Aaron Bono 2006-10-04 01:15:49 Re: timestamps over the web - suggestions
Previous Message chester c young 2006-10-03 21:44:12 timestamps over the web - suggestions