Re: selecting timestamp

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: chris <chrisk(at)pgsqlrocket(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: selecting timestamp
Date: 2018-02-27 20:25:20
Message-ID: 3a7ad900-251d-2b04-602c-b478e792f0bc@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 02/27/2018 12:16 PM, chris wrote:
>
> What is the best way of selecting current timestamp in UTC?
>
> SELECT
> CURRENT_TIMESTAMP   as ct1

Well the above would depend on your database having its time zone
set to UTC.

> ,timezone('UTC',CURRENT_TIMESTAMP) as ct2
> ,timezone('utc',now()) as ct3
> ,CURRENT_TIMESTAMP at time zone 'UTC' as ct4
> ,NOW() at time zone 'utc' as ct5

The rest would do the job. The question becomes where are you planning
on calling these and what is tine you are looking for? See the below for
more information:

https://www.postgresql.org/docs/10/static/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT

Basically the functions act differently in transactions, which will
affect the time returned.

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2018-02-27 20:26:27 Re: selecting timestamp
Previous Message chris 2018-02-27 20:16:37 selecting timestamp