Re: Formatting an Interval

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Jamison Roberts <jamisonroberts(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Formatting an Interval
Date: 2004-12-31 19:41:18
Message-ID: 20041231194118.GA23987@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, Dec 31, 2004 at 11:37:32AM -0500, Jamison Roberts wrote:

> All of the functions that i've looked at seem to only extract parts
> from Intervals. What I need to do is to format the interval. For
> instance, I have a Interval with the value 1 day 07:57:52. I would
> like that in HH:MM:SS. So in the example the output would be
> 31:57:52.

I'm not aware of a built-in way to get such a format; somebody
please correct me if I'm mistaken.

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.

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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message TJ O'Donnell 2005-01-01 19:20:36 Re: Function in C++
Previous Message Jamison Roberts 2004-12-31 16:37:32 Formatting an Interval