Re: Sum of Intervals

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Plant Thomas <Thomas(dot)Plant(at)lvh(dot)it>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Sum of Intervals
Date: 2003-02-12 15:37:53
Message-ID: 20030212153753.GA14331@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Feb 12, 2003 at 15:37:07 +0100,
Plant Thomas <Thomas(dot)Plant(at)lvh(dot)it> wrote:
> Hello,
>
> I'm trying to do a sum() of some time intervals.
> I get the result as: '1 day 02:30' which is ok, but is there a function
> which converts this to hours or do I have to write my own?
> For example the '1 day 02:30' should become 26:30 hours.

You can get the seconds using extract and then do further manipulation.
To get fractional hours you can use the example below. To get hours and
minutes you can use modular arithmatic and concatenate to build the
desired string.

area=> select extract(epoch from '1 day 02:30'::interval) / 3600;
?column?
----------
26.5
(1 row)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Dmitry Tkach 2003-02-12 17:55:22 Re: timestamp
Previous Message Jr. 2003-02-12 14:59:58 Re: PL/Pgsql trigger function problem.