Maison  >  Article  >  base de données  >  PHP date(/Datetime::W3C)插入日期格式提示错误_MySQL

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

WBOY
WBOYoriginal
2016-06-01 13:11:14927parcourir

详情如下

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


Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn