Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HowTo? CURRENT_TIMESTAMP AT TIME ZONE 'UTC'

Tags:

How would I amend my calls to

sqlalchemy.func.current_timestamp() 

with something that generates

CURRENT_TIMESTAMP AT TIME ZONE 'UTC' 
like image 867
Jonathan Vanasco Avatar asked Mar 15 '13 03:03

Jonathan Vanasco


People also ask

What is my timezone in UTC?

Current time: 16:36:48 UTC. UTC is replaced with Z that is the zero UTC offset. UTC time in ISO-8601 is 16:36:48Z. Note that the Z letter without a space.

Is Postgres now () in UTC?

PostgreSQL stores the timestamptz in UTC value.

How do I get the UTC timestamp in PostgreSQL?

timezone('UTC', now()) turns our current time (of type timestamp with time zone) into the timezonless equivalent in UTC . E.g., SELECT timestamp with time zone '2020-03-16 15:00:00-05' AT TIME ZONE 'UTC' will return 2020-03-16T20:00:00Z .


1 Answers

A quick fix would be to do the following:

func.current_timestamp().op('AT TIME ZONE')('UTC') 

A more proper way is to use compiler extension and define custom compilation of CURRENT_TIMESTAMP. Actually, there's already an example in its docs, which uses a different approach (TIMEZONE function). Since you only need this for Postgres (I assume from your previous emails in SA mailing list that you're using Postgres), here's another (nicer) quick fix:

func.timezone('UTC', func.current_timestamp()) 
like image 69
Audrius Kažukauskas Avatar answered Oct 14 '22 05:10

Audrius Kažukauskas