Re: TIMESTAMP SUBTRACTION - Mailing list pgsql-general

From Joseph Healy
Subject Re: TIMESTAMP SUBTRACTION
Date
Msg-id 1053525993.3775.2.camel@joedesk.hollowcore.com.au
Whole thread Raw
In response to TIMESTAMP SUBTRACTION  ("Madhavi Daroor" <madhavi@zoniac.com>)
Responses Re: TIMESTAMP SUBTRACTION  (Darren Ferguson <darren@crystalballinc.com>)
List pgsql-general
Hi,

You could use something like this, although it might depend on how many
days you were expecting:


select substring((TO_TIMESTAMP('05-21-2003 00:40:00','mm-dd-yyyy')
-TO_TIMESTAMP('04-30-2003 00:00:00','mm-dd-yyyy'))::text from 0 for
3)::int as test;

Hope this helps,

Joe Healy

On Wed, 2003-05-21 at 20:57, 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.
>
> I need to compare this difference with a numeric value in my WHERE clause
> like this
>
> WHERE
>     TIMESTAMP('05-21-2003 00:00:00','mm-dd-yyyy') - TO_TIMESTAMP('04-30-2003
> 00:00:00','mm-dd-yyyy') > 30
>
> But if I do this....I get wrong results. How do I do such a comparison? Or
> How to I get a Numeric value after the subtraction?
>
>
> Please reply SOON !!!
>
> Thanx,
> Madhavi Daroor
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)



pgsql-general by date:

Previous
From: "alex b."
Date:
Subject: caching query results
Next
From: "alex b."
Date:
Subject: Re: Fwd: Re: mod_perl + PostgreSQL implementation