Skip to main content

CONVERT_TZ

Description​

Converts a datetime value from the time zone specified by from_tz to the time zone specified by to_tz, and returns the resulting value. Special cases:

  • If the parameters are invalid, the function returns NULL.

Syntax​

CONVERT_TZ(<dt>, <from_tz>, <to_tz>)

Parameters​

ParameterDescription
<dt>The datetime value to be converted
<from_tz>The original time zone of dt
<to_tz>The target time zone to convert to

Return Value​

Returns the calculated date.

Examples​

select CONVERT_TZ('2019-08-01 13:21:03', 'Asia/Shanghai', 'America/Los_Angeles');
+---------------------------------------------------------------------------+
| convert_tz('2019-08-01 13:21:03', 'Asia/Shanghai', 'America/Los_Angeles') |
+---------------------------------------------------------------------------+
| 2019-07-31 22:21:03 |
+---------------------------------------------------------------------------+
select CONVERT_TZ('2019-08-01 13:21:03', '+08:00', 'America/Los_Angeles');
+--------------------------------------------------------------------+
| convert_tz('2019-08-01 13:21:03', '+08:00', 'America/Los_Angeles') |
+--------------------------------------------------------------------+
| 2019-07-31 22:21:03 |
+--------------------------------------------------------------------+