Re: subtracting minutes from date

From: "Chandra Sekhar Surapaneni" <chandu(at)positivenetworks(dot)net>
To: "Brandon Metcalf" <bmetcalf(at)nortel(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: subtracting minutes from date
Date: 2006-02-23 21:06:59
Message-ID: 0F7F9A82BB0DBB4396A9F8386D0E0612ACD938@pos-exch1.corp.positivenetworks.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You can just save it as timestamp and try the following query.

select * from table where date < (now() - interval '1 hour');

Regards
Chandra Sekhar Surapaneni

-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Brandon Metcalf
Sent: Thursday, February 23, 2006 1:56 PM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] subtracting minutes from date

What is the best way to store a timestamp if all I need to do is select
rows where this timestamp is less than 60 minutes prior to the current
time?

If I have a column called date with data type timestamp without time
zone I know I can use

SELECT * FROM table WHERE date < (now()::DATE - 7)::TIMESTAMP;

to select rows where date is older than seven days. I'm not quite sure
how to interpret now()::DATE::TIMESTAMP since I'm not able to answer my
own question. I've tried things like:

SELECT * FROM table WHERE date < now()::DATE::(TIMESTAMP - 60);

but this gives a syntax error.

Thanks.

--
Brandon

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
message can get through to the mailing list cleanly

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2006-02-23 21:08:32 Re: subtracting minutes from date
Previous Message Karl Wright 2006-02-23 20:49:09 How do I prevent binding to TCP/IP port outside of localhost?