Re: timestamp/date comparison

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: timestamp/date comparison
Дата
Msg-id 8784.1076864708@sss.pgh.pa.us
обсуждение исходный текст
Ответ на timestamp/date comparison  ("Campano, Troy" <Troy.Campano@LibertyMutual.com>)
Список pgsql-general
"Campano, Troy" <Troy.Campano@LibertyMutual.com> writes:
> anna> SELECT request_date,TO_DATE(request_date,'YYYY-MM-DD HH24:MM:SS')

The correct way to write the format string would have been

SELECT request_date,TO_DATE(request_date,'YYYY-MM-DD HH24:MI:SS')

(minutes are MI not MM).  It was evidently taking the minute number as
month number, and not noticing that the field was out of range :-(.
People have complained before that to_date() and related functions don't
detect all the error cases one would reasonably expect them to complain
about ...

However, this all seems like the hard way to solve your problem.
Why don't you just cast the timestamp value to date type, ie
"CAST(request_date AS date)", or just "request_date::date" if you don't
mind using a Postgres-specific syntax.  The date_trunc() function also
is worth knowing about.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: PostgreSQL in a shared-disk enviroment
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Using NOTIFY... Slow Client Querys