Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid datetime format: 1292 Incorrect datetime value [duplicate]

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

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

My PHP code uses PDO

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

the SQL the lastupdated, datatype is datetime

Existing data

enter image description here

like image 263
user580950 Avatar asked Feb 27 '17 15:02

user580950


1 Answers

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

i.e. :

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

From documentation :

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'.

like image 116
JazZ Avatar answered Sep 21 '22 12:09

JazZ