Re: date versus datetime?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Eric McKeown <ericm(at)palaver(dot)net>
Cc: pgsql-sql(at)hub(dot)org
Subject: Re: date versus datetime?
Date: 1998-08-01 20:16:28
Message-ID: 18511.902002588@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Eric McKeown <ericm(at)palaver(dot)net> writes:
> for instance, it seems I can do this with the date type:
> select * from table where date_field < some_date_I_specify_here
> However, if my reading of the manual and my experiments are correct, I
> can't perform that sort of operation with the datetime type.

You certainly can do that with datetime; I do it all the time.
Without seeing a concrete example, I'm not sure why it's not working for
you. Perhaps you are writing the comparison date in a format that's
acceptable for type "date" but not for "datetime"? That doesn't seem
very likely though; datetime's parser is relatively flexible.

There are a couple of gotchas in writing datetime constants in SQL
commands. You have to put quotes around them (they're strings as
far as the parser is concerned). For example,
select * from ohistory where ordertime < 'jun 10 1998 16:00';
In some situations you may have to explicitly cast the string constant
to datetime type:
select * from ohistory where ordertime < 'jun 10 1998 16:00'::datetime;
but I find Postgres usually manages to figure out for itself that a
datetime value is wanted.

As far as I know those gotchas also apply to date constants, however.
So I'm still confused about why one works and not the other for you.

regards, tom lane

Browse pgsql-sql by date

  From Date Subject
Next Message Peter T Mount 1998-08-01 22:48:30 Re: [ADMIN] Authentication Problems
Previous Message Marc Howard Zuckman 1998-08-01 14:31:55 Re: [SQL] pg_time