Re: Interval Formatting -> Convert to timestamp - Mailing list pgsql-general

From Raymond O'Donnell
Subject Re: Interval Formatting -> Convert to timestamp
Date
Msg-id 48AD357D.7050409@iol.ie
Whole thread Raw
In response to Interval Formatting -> Convert to timestamp  ("Ow Mun Heng" <ow.mun.heng@wdc.com>)
List 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@iol.ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

pgsql-general by date:

Previous
From: Shashwat_Nigam
Date:
Subject: Re: [ADMIN] Regarding access to a user
Next
From: Tomasz Ostrowski
Date:
Subject: Re: Interval Formatting -> Convert to timestamp