I am new to postgreSQL and to my surprise there appears to be no single function equivalent to UTC_DATE()
from MySQL.
I was able to get desired result using a combination of date & timezone functions but I am wondering what is the fastest way to do this.
I just want to get UTC date part, at 00:00:00 time of current day.
PostgreSQL assumes your local time zone for any type containing only date or time. All timezone-aware dates and times are stored internally in UTC .
MySQL - UTC_DATE() Function The MYSQL UTC_DATE() is used to get the current UTC date. The resultant value is a string or a numerical value based on the context and, the date returned will be in the 'YYYY-MM-DD' or YYYYMMDD format.
If they're all local to you, then here's the offset: SELECT GETDATE() AS CurrentTime, GETUTCDATE() AS UTCTime. SELECT DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), YOUR_DATE);
Use the time zone capability of PostgreSQL:
SELECT
CAST(NOW() at time zone 'utc' AS date);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With