Re: date comparisons

From: Erik Jones <erik(at)myemma(dot)com>
To: "Belinda M(dot) Giardine" <giardine(at)bio(dot)cse(dot)psu(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: date comparisons
Date: 2006-12-12 16:46:16
Message-ID: 457EDCD8.1050102@myemma.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-patches

Belinda M. Giardine wrote:
> This should be simple but I am missing something. I am trying to extract
> all records entered after a given date. The table has a field
> date_entered which is a timestamp. In this particular case I am not
> worried about time.
>
> I have tried:
> select id from main_table where
> date_entered > to_timestamp('January 2006', 'Month YYYY');
>
> select id from main_table where
> (to_timestamp('January 2006', 'Month YYYY'), now()) overlaps (date_entered, date_entered);
>
> Both of these return all the rows in the table. Half of the rows are
> dated 2000-06-22 12:00:00.
>
> PostgreSQL version 8.1.4
>
I think people often make date comparisons too difficult in postgres.

select id
from main_table
where date_entered >= '2006-01-01';

There are built in conversions for formatted date strings.

--
erik jones <erik(at)myemma(dot)com>
software development
emma(r)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tomi N/A 2006-12-12 16:47:34 a question on SQL
Previous Message Tony Caduto 2006-12-12 16:44:34 Re: Running initdb from another process

Browse pgsql-patches by date

  From Date Subject
Next Message Belinda M. Giardine 2006-12-12 17:03:20 Re: date comparisons
Previous Message Belinda M. Giardine 2006-12-12 16:32:47 date comparisons