gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 06:38:44 26 4
gpt4 key购买 nike

在我的数据库表中有一个 created_at 列,其中包含 Y-m-d H:i:s GMT+7 格式的记录,我想更新所有 created_at记录成UTC格式,例如:

/*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|
+-------------------+

最佳答案

使用 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

关于MySQL 将日期时间记录从 GMT+7 更新为 UTC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52604059/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com