Обсуждение: Error in date_trunc function?

Поиск
Список
Период
Сортировка

Error in date_trunc function?

От
Marat Khairullin
Дата:
Compare TZ part of date_func function output with param 'month' and other.
Is it error?

netquote=> select date_trunc('century', now());
       date_trunc
------------------------
 2000-01-01 00:00:00+03
(1 row)

netquote=> select date_trunc('year', now());
       date_trunc
------------------------
 2001-01-01 00:00:00+03
(1 row)

netquote=> select date_trunc('month', now());
       date_trunc
------------------------
 2001-10-01 00:00:00+04
(1 row)

netquote=> select date_trunc('day', now());
       date_trunc
------------------------
 2001-10-31 00:00:00+03
(1 row)

netquote=> select date_trunc('hour', now());
       date_trunc
------------------------
 2001-10-31 18:00:00+03
(1 row)

netquote=> select date_trunc('minute', now());
       date_trunc
------------------------
 2001-10-31 18:12:00+03
(1 row)

netquote=> select date_trunc('second', now());
       date_trunc
------------------------
 2001-10-31 18:12:24+03
(1 row)

--
Marat Khairullin        8->     mailto:xmm@rambler.ru
                                   Marat.Khairullin@f92.n5049.z2.fidonet.org

Re: Error in date_trunc function?

От
Tom Lane
Дата:
Marat Khairullin <xmm@rambler.ru> writes:
> Compare TZ part of date_func function output with param 'month' and other.
> Is it error?

Depends.  Do those various dates fall in daylight-savings or standard-time
territory in your timezone?  They all look like reasonable candidates
for local midnight to me, if you are in a northern-hemisphere zone that
switches to standard time sometime during October.

            regards, tom lane

Re: Error in date_trunc function?

От
Thomas Lockhart
Дата:
...
> netquote=> select date_trunc('month', now());
>        date_trunc
> ------------------------
>  2001-10-01 00:00:00+04

This one rotated the time back to daylight savings time (the transition
date was in October), hence the one hour jump from now(). You certainly
would not want to somehow preserve a time zone into a date for which it
is invalid, right?

                     - Thomas