Re: calculating elapsed times between timestamps - Mailing list pgsql-general

From Scott Marlowe
Subject Re: calculating elapsed times between timestamps
Date
Msg-id dcc563d10902030108o55a12bcco1dfa3298d1aaab0a@mail.gmail.com
Whole thread Raw
In response to calculating elapsed times between timestamps  (rhubbell <Rhubbell@iHubbell.com>)
Responses Re: calculating elapsed times between timestamps  (rhubbell <Rhubbell@iHubbell.com>)
List pgsql-general
On Mon, Feb 2, 2009 at 5:54 PM, rhubbell <Rhubbell@ihubbell.com> wrote:
>
> I want to find the length of those intervals.
>
> select timestamp, timeelapsed, bobble from perf where bobble like "pokerflat"
> and timeelapsed > 0.4;
>
> The records returned by that query will have an oldest and newest timestamp for
> which I would like to calculate the interval.

The easiest way is to just subtract one timestamp from another...  If
you want the difference in seconds, then use extract

select '2009-01-31 12:34'::timestamp - '2009-01-12 15:34'::timestamp;
     ?column?
------------------
 18 days 21:00:00
select extract(epoch from '2009-01-31 12:34'::timestamp - '2009-01-12
15:34'::timestamp);
 date_part
-----------
   1630800

Does that get you closer to an answer?

pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: Smartest way to resize a column?
Next
From: Kokas Zsolt
Date:
Subject: embedded pgsql media-failure