在我的数据库表中,有一个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|
+-------------------+
答案 0 :(得分:2)
使用CONVERT_TZ(created_at,'+ 00:00','-7:00'):
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