Re: cast time interval to seconds - Mailing list pgsql-general

From Pavel Stehule
Subject Re: cast time interval to seconds
Date
Msg-id 162867790709100907u44b6f45dj4b32a21afbbc95db@mail.gmail.com
Whole thread Raw
In response to Re: cast time interval to seconds  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
2007/9/10, Martijn van Oosterhout <kleptog@svana.org>:
> On Mon, Sep 10, 2007 at 08:44:07PM +0500, rihad wrote:
> > Hi, I have two columns start_time & stop_time declared as "TIME". I'd
> > like to compute the difference between the two times in seconds, all in db:
> >
> > SELECT
> >   (CAST(stop_time AS SECONDS) + 86400 - CAST(start_time AS SECONDS))
> >   % 86400;
>
> At a guess I'd say you should simply subtract the two (ie stop_time -
> start_time) and then use extract() to pull the seconds out.
>
> Have a nice day,
> --
> Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> > From each according to his ability. To each according to his ability to litigate.
>

sample:postgres=# select extract(epoch from time '10:01:30' - time '10:00:00');
 date_part
-----------
        90
(1 row)

Regards
Pavel Stehule

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: cast time interval to seconds
Next
From: Ron Johnson
Date:
Subject: Re: Time Zone design issues