Re: TIMESTAMP SUBTRACTION

From: Joseph Healy <j(dot)healy(at)ugrad(dot)unimelb(dot)edu(dot)au>
To: Madhavi Daroor <madhavi(at)zoniac(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: TIMESTAMP SUBTRACTION
Date: 2003-05-21 14:06:29
Message-ID: 1053525993.3775.2.camel@joedesk.hollowcore.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)postgresql(dot)org)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Johnson, Shaunn 2003-05-21 14:18:04 DBI connection to multiple database
Previous Message Shridhar Daithankar 2003-05-21 12:25:03 Re: TIMESTAMP SUBTRACTION