Selecting rows where timestamp between two timestamps

Started by Jeff Lanzarottaover 18 years ago3 messagesgeneral
Jump to latest
#1Jeff Lanzarotta
delux256-postgresql@yahoo.com

Hello,

I am trying to get this query to work with no luck...

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...

Any ideas?

Thanks.

-Jeff

#2Michael Fuhr
mike@fuhr.org
In reply to: Jeff Lanzarotta (#1)
Re: Selecting rows where timestamp between two timestamps

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

#3Jeff Lanzarotta
delux256-postgresql@yahoo.com
In reply to: Michael Fuhr (#2)
Re: Selecting rows where timestamp between two timestamps

Well that was easy enough... Thanks!

Michael Fuhr <mike@fuhr.org> wrote: 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