I have a MySQL table with a DATETIME NOT NULL
data type (didn't specify default value).
For MySQL default, if I don't specify data, the value will become 0000-00-00 00:00:00
.
Then I fetch the value from database, which value is 0000-00-00 00:00:00
. Then I try to create a DateTime object with the retrieved data.
$date = new DateTime('0000-00-00 00:00:00');
$formatted_date = $date->format('Y-m-d');
echo $formatted_date; // which display -0001-11-30, an obvious invalid date
What is the best way to check if the value is not a valid date ?