pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Sum of Intervals
2+ messages / 2 participants
[nested] [flat]

* Sum of Intervals
@ 2003-02-12 14:37  Plant Thomas <Thomas.Plant@lvh.it>
  0 siblings, 1 reply; 2+ messages in thread

From: Plant Thomas @ 2003-02-12 14:37 UTC (permalink / raw)
  To: pgsql-sql

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.

Thanks for any advice,
Thomas



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Sum of Intervals
@ 2003-02-12 15:37  Bruno Wolff III <bruno@wolff.to>
  parent: Plant Thomas <Thomas.Plant@lvh.it>
  0 siblings, 0 replies; 2+ messages in thread

From: Bruno Wolff III @ 2003-02-12 15:37 UTC (permalink / raw)
  To: Plant Thomas <Thomas.Plant@lvh.it>; +Cc: pgsql-sql

On Wed, Feb 12, 2003 at 15:37:07 +0100,
  Plant Thomas <Thomas.Plant@lvh.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)




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2003-02-12 15:37 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-02-12 14:37 Sum of Intervals Plant Thomas <Thomas.Plant@lvh.it>
2003-02-12 15:37 ` Bruno Wolff III <bruno@wolff.to>

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