From: | Raymond O'Donnell <rod(at)iol(dot)ie> |
---|---|
To: | Ow Mun Heng <ow(dot)mun(dot)heng(at)wdc(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Interval Formatting -> Convert to timestamp |
Date: | 2008-08-21 09:29:33 |
Message-ID: | 48AD357D.7050409@iol.ie |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 21/08/2008 10:09, Ow Mun Heng wrote:
> I want to find out if there's a method to change this
>
> select to_char('1 day 09:18:42.37996'::interval,'HH24:MI:SS')
>
> to something like
>
> 24+9(hours) = 33:18:42 instead of returning It as 09:19:42
I had to do something like this recently when adding up the durations of
music CD tracks (stored as INTERVALs), and I wanted the totals returned
in terms of minutes rather than hours:
create or replace function format_duration(theDuration interval)
returns text
as
$$
select
to_char(extract(hour from $1) * 60 + extract(minute from $1), 'FM9,999')
|| to_char(extract(second from $1), '":"FM00');
$$
language sql;
HTH,
Ray.
------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod(at)iol(dot)ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------
From | Date | Subject | |
---|---|---|---|
Next Message | Vishal Arora | 2008-08-21 09:39:43 | Re: Regarding access to a user |
Previous Message | Shashwat_Nigam | 2008-08-21 09:25:05 | Re: Regarding access to a user |