Re: date ranges in where - Mailing list pgsql-general

From Jasen Betts
Subject Re: date ranges in where
Date
Msg-id gtuifa$urb$3@reversiblemaps.ath.cx
Whole thread Raw
In response to date ranges in where  (Miguel Miranda <miguel.mirandag@gmail.com>)
Responses Re: date ranges in where  (Raymond O'Donnell <rod@iol.ie>)
List pgsql-general
On 2009-05-06, Miguel Miranda <miguel.mirandag@gmail.com> wrote:
> --00032557620e737136046944dbf1
> Content-Type: text/plain; charset=ISO-8859-1
> Content-Transfer-Encoding: 7bit
>
> Hi, what is the recommended way to select a range of dates?

if you want to compare dates, use dates!

> Lets say a have a table with a lastlogin (timestamp) column and i want
> toknow what users logged in for last time between 2009-05-01 and 2009-05-02?
>
> I know that a simple
>
> where lastlogin between '2009-05-01' and '2009-05-02' doesnt work beacuse it
> doesnt include who logged in 2009-05-02 15:30:00, etc...

If you are comparing dates it does.

where lastlogin::date between '2009-05-01'::date and '2009-05-02'::date

If you leave it uncast postgres will probably convert the lastlogin to
a string and produce results other than that desired and proabaly
take longer to do it too.



pgsql-general by date:

Previous
From: "Markus Wollny"
Date:
Subject: Question about function returning record
Next
From: Raymond O'Donnell
Date:
Subject: Re: date ranges in where