pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: chris <chrisk@pgsqlrocket.com>
To: Postgres General <pgsql-general@postgresql.org>
Subject: Re: selecting timestamp
Date: Tue, 27 Feb 2018 12:25:20 -0800
Message-ID: <3a7ad900-251d-2b04-602c-b478e792f0bc@aklaver.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

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.klaver@aklaver.com




view thread (5+ messages)  latest in thread

Message-ID: <3a7ad900-251d-2b04-602c-b478e792f0bc@aklaver.com>
Permalink:  ../3a7ad900-251d-2b04-602c-b478e792f0bc@aklaver.com/
Also on:    postgresql.org/message-id/3a7ad900-251d-2b04-602c-b478e792f0bc@aklaver.com

 · 

reply

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: adrian.klaver@aklaver.com, chrisk@pgsqlrocket.com
  Subject: Re: selecting timestamp
  In-Reply-To: <3a7ad900-251d-2b04-602c-b478e792f0bc@aklaver.com>
  References: <0a80c0d7-3c90-3051-3835-8d973db8bdc4@pgsqlrocket.com> <32ecec3a-654d-25e5-75ea-ccd7e2331429@pgsqlrocket.com> <3a7ad900-251d-2b04-602c-b478e792f0bc@aklaver.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