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β
Parameter | Description |
---|---|
<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 |
+--------------------------------------------------------------------+