Re: Formatting an Interval - Mailing list pgsql-sql

From Michael Fuhr
Subject Re: Formatting an Interval
Date
Msg-id 20050102163940.GA37196@winnie.fuhr.org
Whole thread Raw
In response to Re: Formatting an Interval  (Karel Zak <zakkr@zf.jcu.cz>)
Responses Re: Formatting an Interval  (Pierre-Frédéric Caillaud<lists@boutiquenumerique.com>)
List pgsql-sql
On Sun, Jan 02, 2005 at 05:19:23PM +0100, Karel Zak wrote:
> On Fri, 2004-12-31 at 12:41 -0700, Michael Fuhr wrote:
>
> > You could write a function to format the interval.  For example,
> > with PL/pgSQL you could use EXTRACT(epoch FROM interval_value) to
> > convert the interval to a number of seconds; convert that to hours,
> > minutes, and seconds; and use TO_CHAR to format the return value.
> 
> to_char() works with standard date/time ranges, for example 1-24 -- so
> there is no way how convert to anything like "31:57:52".

TO_CHAR() works with several types, including integer, numeric, and
double precision.  If you've broken the interval into three variables,
one containing hours, one containing minutes, and one containing
seconds, then you can use TO_CHAR() to add leading zeroes where
needed.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


pgsql-sql by date:

Previous
From: Karel Zak
Date:
Subject: Re: Formatting an Interval
Next
From: Kretschmer Andreas
Date:
Subject: Re: Formatting an Interval