Re: timestamp/date comparison

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: "Campano, Troy" <Troy(dot)Campano(at)LibertyMutual(dot)com>
Cc: Postgres general mailing list <pgsql-general(at)postgresql(dot)org>
Subject: Re: timestamp/date comparison
Date: 2004-02-13 18:27:10
Message-ID: 20040213102108.C24172@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 13 Feb 2004, Campano, Troy wrote:

> Hi,
> I'm trying to compare a timestamp to current_timestamp but I'm having
> trouble.
> I want to compare just the date piece of my timestamp column to just the
> date piece of current_timestamp.
>
> I'm getting weird results that I don't understand.
> When I use TO_DATE it changes the year, month, etc.

I think you probably don't want to_date in any case. CAST(whatever AS
DATE) is probably better. The to_date way probably is taking the
timestamp converting it to text and then attempting to convert the text
back.

> anna=> SELECT request_date,TO_DATE(request_date,'YYYY-MM-DD HH24:MM:SS')

Here, you're using the minutes as month information I think.

> anna=> SELECT
> TO_DATE(request_date,'MM/DD/YYYY'),TO_DATE(current_timestamp,'MM/DD/YYYY
> ') FROM anna_onestop_database_t WHERE TO_DATE(request_date,'MM/DD/YYYY')
> > TO_DATE(current_timestamp,'MM/DD/YYYY');

I'm not sure why this is working at all, but using the standard output
format for a timestamp, it doesn't follow the form MM/DD/YYYY I believe,
so the format string doesn't really line up with the data.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rick Gigger 2004-02-13 18:59:10 resource monitoring
Previous Message Iker Arizmendi 2004-02-13 18:24:09 client IP address