From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Gauthier <davegauthierpg@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: timestamp (military) at time zone without the suffix
Date: Wed, 11 Jul 2018 15:54:36 -0400
Message-ID: <5402.1531338876@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMBRECB=k1CkGjvY-nn=WMtcVFM8f_88D6MK+Bt=jCbHVOpbWA@mail.gmail.com>
References: <CAMBRECB=k1CkGjvY-nn=WMtcVFM8f_88D6MK+Bt=jCbHVOpbWA@mail.gmail.com>
David Gauthier <davegauthierpg@gmail.com> writes:
> sqfdev=> select now()::timestamp(0) at time zone 'utc' ;
> timezone
> ------------------------
> 2018-07-11 11:27:12-04
> (1 row)
You're doing it wrong: coercing to timestamp already involves a rotation
to local time, and then "at time zone" says to interpret that as a time
in UTC, and the output is a timestamptz which will be displayed in your
local time.
I think the result you want is more like
select (now() at time zone 'utc')::timestamp(0);
although personally I'd choose some other way of dropping the fractional
second, probably
select current_timestamp(0) at time zone 'utc';
regards, tom lane
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: tgl@sss.pgh.pa.us, davegauthierpg@gmail.com
Subject: Re: timestamp (military) at time zone without the suffix
In-Reply-To: <5402.1531338876@sss.pgh.pa.us>
References: <CAMBRECB=k1CkGjvY-nn=WMtcVFM8f_88D6MK+Bt=jCbHVOpbWA@mail.gmail.com> <5402.1531338876@sss.pgh.pa.us>
* 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