postgresql - Postgres: get local timestamp with time zone of latest midnight -


i'm in time zone europe/berlin (+02), postgresql running @ utc (+00). need timestamp time zone @ latest local midnight date (the start of day date of current day in time zone).

so end result if have 2013-03-03 14:00:00+02

2013-03-03 22:00:00+00 2013-03-04 00:00:00+02 // same 

i tried date with

select timestamp 'today' @ time zone 'europe/berlin' 

unfortunately yields wrong date (the previous day midnight) during 00:00 , 02:00 utc time stil @ previous day , today seems use utc calculate rest.

if have 2013-03-03 00:05 @ europe/berlin return

2013-05-01 22:00:00+00 

if want have correct date need use

select date_trunc('day', now() @ time zone 'europe/berlin') @ time zone 'europe/berlin'; 2013-05-02 22:00:00+00 

which correct, quite ugly.

is there cleaner variant of command?

use timestamptz. tz @ end meaning with time zone:

select timestamptz 'today' @ time zone 'europe/berlin' 

or if more explicit:

select timestamp time zone 'today' @ time zone 'europe/berlin' 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -