Re: Date difference in seconds

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Raghunath T <raghunatht(at)mindtree(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Date difference in seconds
Date: 2001-02-23 18:51:14
Message-ID: Pine.BSF.4.21.0102231050100.17822-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 19 Feb 2001, Raghunath T wrote:

> Hi ,
> Please consider the following schema and the query given below and
> let me know how to get the results I want.
>
> CREATE TABLE temp (
> id INTEGER NOT NULL,
> start_time TIMESTAMP,
> end_time TIMESTAMP,
> PRIMARY KEY (id)
> );
>
> Now I want the difference between start time and end time in seconds.
> Select date_part('seconds',start_time - end_time) from temp; gives
> me only the difference between the seconds value in both timestamps. It
> ignores all the days, hrs, minutes etc.
>
> My problem is that I want the actual difference between the two timestamps
> expressed in seconds.

You should be able to get that with date_part('epoch', start_time-end_time)
(or more likely end_time-start_time unless you want a negative number)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-02-23 20:04:24 Re: Still having some install problems.
Previous Message Adam Haberlach 2001-02-23 18:42:07 ...lame use of casting, looking for workaround...