I am having a problem inserting DATETIME into MySQL using PHP.
First, I am fetching a date from the news table:
$statement = $db->query("SELECT utcPublishedDate FROM News WHERE idNews = $newsID");
$row = $statement->fetch(PDO::FETCH_ASSOC);
$utcPublishedDate = $row["utcPublishedDate"];
Then I am doing some date manipulation on that date due to some code requirements, eventually this date is changing to something else.
Now, I have to update the table, so:
$statement = $db->query("UPDATE News SET utcPublishedDate = $utcPublishedDate WHERE idNews = $newsID");
This is causing an error. If I do this:
$statement = $db->query("UPDATE News SET utcPublishedDate = NOW() WHERE idNews = $newsID");
The statement will execute without a problem.
Now, how do I solve the error I am getting? Obviously It is something to do with the fact there are spaces in my DATETIME field. Suggestions please? Thanks.
try changing:
to: