Re: Selecting rows where timestamp between two timestamps

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Jeff Lanzarotta <delux256-postgresql(at)yahoo(dot)com>
Cc: PostgreSQL GENERAL List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Selecting rows where timestamp between two timestamps
Date: 2007-08-13 14:37:31
Message-ID: 20070813143728.GA91805@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Aug 13, 2007 at 07:16:30AM -0700, Jeff Lanzarotta wrote:
> select * from foobar where ts between now() and now() - interval '5 days'
>
> btw, the column ts is defined as:
>
> ts timestamp with time zone NOT NULL DEFAULT now()
>
> No rows are returned, but I know there are at least 100 rows that should be returned...

Put the lower value first or use BETWEEN SYMMETRIC:

select * from foobar where ts between now() - interval '5 days' and now()
select * from foobar where ts between symmetric now() and now() - interval '5 days'

--
Michael Fuhr

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Lanzarotta 2007-08-13 14:43:08 Re: Selecting rows where timestamp between two timestamps
Previous Message Scott Marlowe 2007-08-13 14:35:13 Re: Persistent connections in PHP