Skip to content

CONVERT_TZ()

Function Description

The CONVERT_TZ() function is used to convert a given date time from one time zone to another. If the parameter is invalid, the function returns NULL.

Function Syntax

> CONVERT_TZ(dt,from_tz,to_tz)

Parameter definition

Parameters Description
dt Required parameters. The given date and time to convert.
from_tz Required parameters. The current time zone identification
to_tz Required parameters. The new time zone's identity

Example

mysql> SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
+-------------------------------------------------------+
| convert_tz(2004-01-01 12:00:00, GMT, MET) |
+-------------------------------------------------------+
| 2004-01-01 13:00:00 |
+-------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT CONVERT_TZ('2004-01-01 12:00:00','+00:00','+10:00');
+------------------------------------------------------------------+
| convert_tz(2004-01-01 12:00:00, +00:00, +10:00) |
+------------------------------------------------------------------+
| 2004-01-01 22:00:00 |
+------------------------------------------------------------------+
1 row in set (0.01 sec)

mysql> select convert_tz('2023-12-31 10:28:00','+08:00', 'America/New_York') as dtime;
+--------------------------+
| dtime |
+--------------------------+
| 2023-12-30 21:28:00 |
+--------------------------+
1 row in set (0.00 sec)

mysql> select convert_tz(NULL,'-05:00', '+05:30') as dtime;
+--------+
| dtime |
+--------+
| NULL |
+--------+
1 row in set (0.00 sec)