i have a problem when i try to insert a time in my database using mysql:
The database is storing the date wrongly as you can see:
The column type is TIMESTAMP
In my code (i am using PHP with codeigniter 4 for this), i have a string date, but the type of the field which is saving the date is TIMESTAMP
$fecha = strtotime($pedido['fecha_creacion']); //Get the date from string and converting it to timestamp
$dbventor->query("INSERT INTO tfacpeda(FECHA)VALUES ($fecha)); //Insert to database, but wrongly
The variable fecha contains a date string like this: "2022-10-07 15:03:10"
can you help me with this?
thanks!
CodePudding user response:
Problem solved!
the issue comes because a confusion, the timestamp doesn't have to be treated in a different way, because the database is expecting to receive a date string
$fecha = $pedido['fecha_creacion'];
$dbventor->query("INSERT INTO tfacpeda(FECHA)VALUES ('$fecha')); //Note the quotes at the variable '$fecha'