Re: date ranges in where

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Miguel Miranda <miguel(dot)mirandag(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: date ranges in where
Date: 2009-05-06 21:16:43
Message-ID: 4A01FE3B.5090605@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 06/05/2009 22:12, Miguel Miranda wrote:
> Hi, what is the recommended way to select a range of 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...

Why not just include the time in the comparisons?

....between '2009-05-01 00:00'::timestamp
and '2009-05-02 23:59:59'::timestamp

Ray.

------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod(at)iol(dot)ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Erik Jones 2009-05-06 21:17:36 Re: date ranges in where
Previous Message Eric Schwarzenbach 2009-05-06 21:16:37 Re: XML -> PG ?