In this article, we will learn how to convert UTC to the local timezone in MySQL.
When we are working with the big database, it is important to manage the default database time zone. MySQL does not store time zone information when storing timestamps. It also uses the host server time as the basis for generating the output of NOW()
function.
Working With Date Time Functions
In MySQL, CONVERT_TZ()
converts a DateTime value dt from the time zone given by from_tz to the time zone given by to_tz and returns the resulting value. This function returns NULL
if the arguments are invalid.
CONVERT_TZ(dt,from_tz,to_tz)
Where,
dt is the date/time,
from_tz is the original time zone and
to_tz is the time zone to convert to.
For Example,
Here is an example of converting timezones using offset timezones.
-- using offset time zones
SELECT CONVERT_TZ('2019-09-01 01:00:00','+00:00','+05:30') AS
Converted_TimeZone;
Converted_TimeZone |
----------------------------
2020-12-01 09:00:00
I hope this article will help you to understand how to convert UTC to the local timezone in MySQL.
Share your valuable feedback, please post your comment at the bottom of this article. Thank you!
Comments