Answer the question
In order to leave comments, you need to log in
How to correctly add a date to a table entry?
The following error occurs when trying to create a record with data of type date:
Uncaught exception: 'PDOException'</p><p>Message: 'SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value: ':end' for column 'timedate' at row 1'
$date = new \DateTime(date('Y-m-d'));
$date->add(new \DateInterval('P'.$period.'D'));
$endDate =$date->format('Y-m-d');
$status = 1;
$pdo = static::getDB();
$query = $pdo->prepare("INSERT INTO Invites (invite,timedate,status) VALUES (':code', ':end',':status')");
$query->bindParam(':code', $code, \PDO::PARAM_INT);
$query->bindParam(':end', $endDate, \PDO::PARAM_STR);
$query->bindParam(':status', $status, \PDO::PARAM_INT);
$query->execute();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question