Re: TIMESTAMP SUBTRACTION - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: TIMESTAMP SUBTRACTION
Date
Msg-id 20030521151128.GB2283@dcc.uchile.cl
Whole thread Raw
In response to TIMESTAMP SUBTRACTION  ("Madhavi Daroor" <madhavi@zoniac.com>)
List pgsql-general
On Wed, May 21, 2003 at 04:27:32PM +0530, Madhavi Daroor wrote:
> Hi All,
>      When I subtract 2 timestamp variables in postgres 2.3.1, I get an
> interval value.
> Eg:
> SELECT TO_TIMESTAMP('05-21-2003 00:00:00','mm-dd-yyyy') -
> TO_TIMESTAMP('04-30-2003 00:00:00','mm-dd-yyyy');
> Result:
>     21 days --------- This is an interval
>
> But what I need is a numeric value. Ie; 21 and NOT 21 days.

One thing you can try is to convert the timestamps to dates, and
substract that.  It'll return a numerical value.

regression=# select to_date('2003-04-99', 'yyyy-mm-dd') -
to_date('2002-13-85', 'yyyy-mm-dd') > 100;
 ?column?
 ----------
  t
  (1 row)

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"I think my standards have lowered enough that now I think 'good design'
is when the page doesn't irritate the living fuck out of me." (JWZ)

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: TIMESTAMP SUBTRACTION
Next
From: Darren Ferguson
Date:
Subject: Re: TIMESTAMP SUBTRACTION