位置:首页 > 数据库 > SQL在线教程 > SQL CONVERT_TZ()函数

SQL CONVERT_TZ()函数

CONVERT_TZ(dt,from_tz,to_tz)

转换datetime值dt从from_tz给出的时区被赋予转到to_tz的时区并返回结果值。 如果参数无效此函数返回NULL。

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.00 sec)