无效的日期时间格式:1292错误的日期时间值 [英] Invalid datetime format: 1292 Incorrect datetime value

查看:2909
本文介绍了无效的日期时间格式:1292错误的日期时间值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用字段(日期时间)更新表时,出现以下错误消息

I am getting below error when I am trying to update a table with a field(datetime)

致命错误:消息为'SQLSTATE [2007]的未捕获异常'PDOException':无效的日期时间格式:1292错误的日期时间值:'up-upupted'列的'02 -27-2017 16:37'

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[2007]: Invalid datetime format: 1292 Incorrect datetime value: '02-27-2017 16:37' for column lastupated

我的PHP代码使用PDO

My PHP code uses PDO

$lastupdated = date('m-d-Y H:i:s');
$run = $conn->prepare($sql);
$run->bindParam(':lastupdated', $lastupdated, PDO::PARAM_STR); 

SQL 最后更新的数据类型为datetime

the SQL the lastupdated, datatype is datetime

现有数据

推荐答案

您需要像"Y-m-d H:i:s"这样格式化日期,才能使用MySQL datetime字段.

You need to format date like "Y-m-d H:i:s" in order to work with MySQL datetime field.

即:

$lastupdated = date('Y-m-d H:i:s');

来自文档:

DATETIME类型用于包含日期和时间部分的值. MySQL检索并以'YYYY-MM-DD HH:MM:SS'格式显示DATETIME值.支持的范围是"1000-01-01 00:00:00"到"9999-12-31 23:59:59".

The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.

这篇关于无效的日期时间格式:1292错误的日期时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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