MySQL将日期时间记录从GMT + 7更新为UTC

时间:2018-10-02 07:50:44

标签: mysql datetime timezone

在我的数据库表中,有一个created_at列,它具有Y-m-d H:i:s GMT + 7格式的记录,我想将所有created_at记录更新为UTC格式,例如: / p>

/*Old Records in GMT+7 format*/
+-------------------+
|    created_at     |
+-------------------+
|2018-09-30 12:11:25|
|2018-10-01 02:44:05|
|2018-10-02 14:45:15|
+-------------------+


/*New Records in UTC format*/
+-------------------+
|    created_at     |
+-------------------+
|2018-09-30 05:11:25|
|2018-09-30 19:44:05|
|2018-10-02 07:45:15|
+-------------------+

1 个答案:

答案 0 :(得分:2)

使用CONVERT_TZ(created_at,'+ 00:00','-7:00'):

demo

SELECT created_at,CONVERT_TZ(created_at,'+00:00','-7:00');

输出:

createddate          utctime
2018-10-02 08:56:29  2018-10-02 01:56:29