How to convert unix timestamp to utc 0 format in mysql?

Member

by shyann , in category: MySQL , 9 months ago

How to convert unix timestamp to utc 0 format in mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by mallory_cormier , 9 months ago

@shyann 

To convert a Unix timestamp to UTC 0 format in MySQL, you can use the FROM_UNIXTIME() and CONVERT_TZ() functions. Here's an example:

1
SELECT CONVERT_TZ(FROM_UNIXTIME(your_unix_timestamp), @@session.time_zone, '+00:00') AS utc_0_time;


Replace your_unix_timestamp with the actual Unix timestamp value you want to convert. The FROM_UNIXTIME() function converts the Unix timestamp to a MySQL datetime value, and the CONVERT_TZ() function converts the datetime value to UTC 0 timezone.


Note that the @@session.time_zone returns the current session's time zone, so this query will return the conversion based on the session's time zone. If you want to convert based on a specific time zone instead of the session's time zone, you can replace @@session.time_zone with the time zone value you desire, like US/Pacific, Asia/Tokyo, etc.


The result of the query will be the equivalent datetime value in UTC 0 format.