Re: timestamp (military) at time zone without the suffix

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Gauthier <davegauthierpg(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: timestamp (military) at time zone without the suffix
Date: 2018-07-11 19:54:36
Message-ID: 5402.1531338876@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

David Gauthier <davegauthierpg(at)gmail(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2018-07-11 19:57:33 Re: timestamp (military) at time zone without the suffix
Previous Message Adrian Klaver 2018-07-11 19:52:44 Re: timestamp (military) at time zone without the suffix