From: Joe Conway <mail@joeconway.com>
To: chris <chrisk@pgsqlrocket.com>
To: Postgres General <pgsql-general@postgresql.org>
Subject: Re: selecting timestamp
Date: Tue, 27 Feb 2018 12:33:46 -0800
Message-ID: <2d002e06-5da4-948b-31c6-0ba367164464@joeconway.com> (raw)
In-Reply-To: <32ecec3a-654d-25e5-75ea-ccd7e2331429@pgsqlrocket.com>
References: <0a80c0d7-3c90-3051-3835-8d973db8bdc4@pgsqlrocket.com>
<32ecec3a-654d-25e5-75ea-ccd7e2331429@pgsqlrocket.com>
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
> ,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
Depends on whether you want a volatile or stable answer:
\x
SELECT clock_timestamp(),
clock_timestamp() AT TIME ZONE 'UTC',
now(),
now() AT TIME ZONE 'UTC'
FROM generate_series(1,3);
-[ RECORD 1 ]---+------------------------------
clock_timestamp | 2018-02-27 12:30:10.46699-08
timezone | 2018-02-27 20:30:10.466991
now | 2018-02-27 12:30:10.466692-08
timezone | 2018-02-27 20:30:10.466692
-[ RECORD 2 ]---+------------------------------
clock_timestamp | 2018-02-27 12:30:10.467017-08
timezone | 2018-02-27 20:30:10.467017
now | 2018-02-27 12:30:10.466692-08
timezone | 2018-02-27 20:30:10.466692
-[ RECORD 3 ]---+------------------------------
clock_timestamp | 2018-02-27 12:30:10.467023-08
timezone | 2018-02-27 20:30:10.467023
now | 2018-02-27 12:30:10.466692-08
timezone | 2018-02-27 20:30:10.466692
HTH,
Joe
--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development
Attachments:
signature.asc (application/pgp-signature, 818B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: mail@joeconway.com, chrisk@pgsqlrocket.com
Subject: Re: selecting timestamp
In-Reply-To: <2d002e06-5da4-948b-31c6-0ba367164464@joeconway.com>
References: <0a80c0d7-3c90-3051-3835-8d973db8bdc4@pgsqlrocket.com> <32ecec3a-654d-25e5-75ea-ccd7e2331429@pgsqlrocket.com> <2d002e06-5da4-948b-31c6-0ba367164464@joeconway.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox