I need to insert the current date in the following format into a TIMESTAMP column in a MySQL db: d-m-Y
As of now I am using SQL NOW()
, which returns the date as Y-m-d
. Because I am using AJAX to display the data I cannot format the returned result using $date_returned->format(d-m-Y)
. Therefore I need to insert the date in the format that I will display on my AJAX call.
I tried to insert the date using the following functions:
1) date('d-m-Y');
2) (new \DateTime())->format('Y-m-d');
I understand these two functions do pretty much the same thing but I was not sure what else I should try.
MySQL threw the following error for both dates:
Error : (1292) Incorrect datetime value: '-2014' for column 'msg_date' at row 1
I am guessing this should be an easy fix but I can't figure out what is wrong.
I tried both TIMESTAMP
and DATETIME
on MySQL's end but neither worked. (I need it to be TIMESTAMP
though).
Any suggestion is welcome!