Error in date_trunc function?

Started by Marat Khairullinover 24 years ago3 messagesgeneral
Jump to latest
#1Marat Khairullin
xmm@rambler.ru

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

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Marat Khairullin (#1)
Re: Error in date_trunc function?

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

#3Thomas Lockhart
lockhart@fourpalms.org
In reply to: Marat Khairullin (#1)
Re: Error in date_trunc function?

...

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