How to check if a variable contains a date or a date and text?

advertisements

How to check whether a variable $date contains a date in the form of 2011-09-20 ? This is to know if the $date contains any letters in it because I want to use the date() and gives me error.


try this:

$date = '2011-09-20';
list($y, $m, $d) = explode("-", $date);
if(checkdate($m, $d, $y)){
    echo "OK Date";
} else {
    echo "BAD Date";
}

demo here: http://codepad.org/3iqrQrey