Re: [GENERAL] Selecting between dates

From: Simon Drabble <simond(at)escape(dot)com>
To: Wim Kerkhoff <wim(at)netmaster(dot)ca>
Cc: Postgresql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: [GENERAL] Selecting between dates
Date: 1999-08-11 03:52:30
Message-ID: Pine.LNX.3.96.990810234738.17670F-100000@dragon
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 10 Aug 1999, Wim Kerkhoff wrote:

> Hi,
>
> I am creating a script that sends out reminders to subscribers to a site who
> have not paid. I can't figure out the math that will add 7 days to a date.
>
> I want something like this:
>
> select * from company where created
> is between (lastpaid + 14 days) and (created + 28 days);
>
> I can't figure out the syntax that will let me add days to a date. I checked
> the archives and the Postgresql doc's, but nothing.
>
> Ideas?
>
> Thanks,
>
> Wim Kerkhoff.
>
>

Use the ::reltime specifier, e.g.

select * from company
WHERE created > (lastpaid + ('14 days'::reltime))::datetime
AND created < (lastpaid + ('28 days'::reltime))::datetime;

Although I suspect you need "- ('14 days'..." if you are talking about the
past.

The date functions are documented very well in the postgres docs, specifically
the user section.

Simon.

--
"Don't anthropomorphise computers - they don't like it."

Simon Drabble It's like karma for your brain.
simon(at)eskimo(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Herouth Maoz 1999-08-11 09:54:17 Re: [GENERAL] repost: unique composite index with boolean fields
Previous Message Wim Kerkhoff 1999-08-11 00:15:51 Re: [GENERAL] Selecting between dates