欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

PHP date(/Datetime::W3C)插入日期格式提示错误_MySQL

程序员文章站 2022-06-14 10:27:03
...
详情如下

select date('2014-05-16T11:13:57+08:00');
+-----------------------------------+
| date('2014-05-16T11:13:57+08:00') |
+-----------------------------------+
| 2014-05-16 |
+-----------------------------------+
1 row in set, 1 warning (0.02 sec)

mysql> select date('2014-05-16T11:13:57+08:00');
+-----------------------------------+
| date('2014-05-16T11:13:57+08:00') |
+-----------------------------------+
| 2014-05-16 |
+-----------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> select date('2014-05-16T11:12:57+08:00');
+-----------------------------------+
| date('2014-05-16T11:12:57+08:00') |
+-----------------------------------+
| 2014-05-16 |
+-----------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> select date_format('2014-05-16T11:13:57+08:00', '%Y-%m-%d %H:%i:%s');
+---------------------------------------------------------------+
| date_format('2014-05-16T11:13:57+08:00', '%Y-%m-%d %H:%i:%s') |
+---------------------------------------------------------------+
| 2014-05-16 11:13:57 |
+---------------------------------------------------------------+
1 row in set, 1 warning (0.03 sec)

mysql> select date_format('2014-05-16T11:13:57+08:00', '%Y-%m-%d %H:%i:%s');
+---------------------------------------------------------------+
| date_format('2014-05-16T11:13:57+08:00', '%Y-%m-%d %H:%i:%s') |
+---------------------------------------------------------------+
| 2014-05-16 11:13:57 |
+---------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

本人mysql版本是5.5.19,执行以上sql这个表明mysql是支持w3c日期格式的。

问题出在那儿呢?最后定位到了mysql可能开启严格检查日期模式,执行

set sql_mode=NO_ENGINE_SUBSTITUTION,这个问题就解决了!!!

不过mysql 重启后这个配置就失效了,最好的方法是修改mysql.ini制空