From: Michael Fuhr <mike@fuhr.org>
To: Karel Zak <zakkr@zf.jcu.cz>
Cc: Jamison Roberts <jamisonroberts@gmail.com>
Cc: List pgsql-sql <pgsql-sql@postgresql.org>
Subject: Re: Formatting an Interval
Date: Sun, 2 Jan 2005 09:39:40 -0700
Message-ID: <20050102163940.GA37196@winnie.fuhr.org> (raw)
In-Reply-To: <1104682763.3610.2.camel@petra>
References: <238e52230412310837183fb730@mail.gmail.com>
<20041231194118.GA23987@winnie.fuhr.org>
<1104682763.3610.2.camel@petra>
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/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mike@fuhr.org, zakkr@zf.jcu.cz, jamisonroberts@gmail.com
Subject: Re: Formatting an Interval
In-Reply-To: <20050102163940.GA37196@winnie.fuhr.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox