Re: cast time interval to seconds

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: rihad <rihad(at)mail(dot)ru>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: cast time interval to seconds
Date: 2007-09-10 16:01:14
Message-ID: 20070910160114.GE16512@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2007-09-10 16:07:06 Re: cast time interval to seconds
Previous Message Michael Glaesemann 2007-09-10 15:58:11 Re: cast time interval to seconds