Mysql
 SQL >> Database >  >> RDS >> Mysql

Impostare una data MySQL con stringa

Metti le virgolette intorno alla data, cioè a $timestring:

"UPDATE posts
SET creatdate = '$timestring'
WHERE postid = 1"

Meglio usare query parametrizzate:

$stmt = $pdo->prepare("UPDATE posts SET creatdate = :date WHERE postid = :id");
$stmt->execute(['date' => $timestring, 'id' => 1]);

Assicurati che la stringa sia nel formato Y-m-d H:i:s.