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

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

WBOY
WBOYOriginal
2016-06-01 13:11:14897browse

详情如下

 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制空


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn