A datetime field that is not set in MySQL will be returned as 0000-00-00 00:00:00
What is the best way to determine if a date is set in PHP?
Not if they work:
if($date) //will return true because it is a valid string if(empty($date)) //will also return true. if(strtotime($date)) //I thought this would work but it returns a negative number and is true.
I could use:
if($date == '0000-00-00 00:00:00')
However, if I ever changed the column type to Date , it will break. Therefore, I do not like it either.
I was looking for something like is_date
, but all I could find was a function called checkdate , which doesn't seem to be what I'm looking for.
I suppose I could use:
if(strtotime($date) > 0)
I do not see any obvious problems with this, but I still thought there might be something better.
What is the standard way?
source share