MySQL datetime:插入带有时区偏移量的日期 [英] MySQL datetime: insert a date with timezone offset

查看:377
本文介绍了MySQL datetime:插入带有时区偏移量的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  INSERT INTO dates VALUES(4,2011-10 -04 12:58:36 -0600)

4只是一个ID。在表中插入为:

  2011-10-04 12:58:36或0000-00-00 00: 00:00 

所以我的问题是,时差-0600丢失。如何插入它呢?

解决方案

您可以使用SUBSTR()将其关闭,并将CONVERT_TZ()转换成。





这样的事情

  INSERT INTO table_name CONVERT_TZ(SUBSTR('2011-10-04 12:58:36 -0600', 1,19),'+ 00:00',SUBSTR('2011-10-04 12:58:36 -0600',20)); 


I tried to insert a timestamp into 'dates' with:

INSERT INTO dates VALUES (4, "2011-10-04 12:58:36 -0600")

4 is just an ID. In the table it is inserted as:

2011-10-04 12:58:36 or 0000-00-00 00:00:00

So my problem is, that the time difference -0600 is lost. How can I insert it, too?

解决方案

You could use SUBSTR() to chop it off and CONVERT_TZ() to convert it.

Something like this

INSERT INTO table_name  CONVERT_TZ(SUBSTR('2011-10-04 12:58:36 -0600',1,19),'+00:00',SUBSTR('2011-10-04 12:58:36 -0600',20));

这篇关于MySQL datetime:插入带有时区偏移量的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆