Re: How to get correct local time

From: Vitaly Burovoy <vitaly(dot)burovoy(at)gmail(dot)com>
To: Andrus <kobruleht2(at)hot(dot)ee>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to get correct local time
Date: 2017-03-29 11:15:05
Message-ID: CAKOSWN=D6JHz4bj8ujkFtiZWAUFzvE2oGGvxUG9=rWgDxCs81w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 3/29/17, Vitaly Burovoy <vitaly(dot)burovoy(at)gmail(dot)com> wrote:
> On 3/29/17, Andrus <kobruleht2(at)hot(dot)ee> wrote:
>>
>> select current_time at time zone 'GMT-2'
>>
>> returns
>>
>> "11:54:40.22045+02"
>>
>> but correct local time in Windows is one hour different:
>>
>> 12:54
>>
>> How to get correct local time ?
>>
>>
>> Using
>>
>> "PostgreSQL 9.6.0, compiled by Visual C++ build 1800, 32-bit"
>>
>> with standard postgresql.conf file in Windows 10
>> Same issue occurs also in ealier Postgres and in earlier windows.
>>
>> Server time in Windows is correct.
>>
>> Daylight saving time was changed by one hour a week ago.
>> Maybe postgres didnt recognized it.
>>
>> Posted also in
>>
>> http://stackoverflow.com/questions/43090328/how-to-return-correct-local-time-in-postgres
>>
>> Andrus.
>>
>
> Try
>
> SELECT now();
>
> or
>
> SELECT current_timestamp;

Oops. I missed you need a time part only.

Why do you use "at time zone" with a constant shift from GMT? If you
want to get your local zone, use just

SELECT current_time;

If you want to get current time in a specified part of the world, use
a region name:

postgres=# SELECT current_time AT TIME ZONE 'Asia/Tokyo', current_time
AT TIME ZONE 'US/Samoa';
timezone | timezone
--------------------+--------------------
20:10:57.924534+09 | 00:10:57.924534-11

Postgres uses set of rules when and how a shift from GMT changed (or
will change by knowledge at the current moment) for the concrete
region.

--
Best regards,
Vitaly Burovoy

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2017-03-29 13:24:25 Re: How to get correct local time
Previous Message Ron Ben 2017-03-29 11:06:58 Re: Request to add feature to the Position function