I want to create a function, to check if $date
is a valid date and time
function validateDate($date){
$format = 'Y-m-d h:i A';// Eg : 2014-09-24 10:19 PM
....
}
I want to check the $date is valid, and it is in given format:
If the statement is true {
function should return corresponding time() of the date using strtotime() or any other functions,,
}Otherwise {
return false
}
You may suggest me to use regex
. But I think it have limitation in the case of feb
,april
,june
,sep
,nov
etc.
I found a code to check if the date is valid.
function validateDate($date){
$d = DateTime::createFromFormat('Y-m-d', $date);
return $d && $d->format('Y-m-d') == $date;
}
function was copied from this answer or php.net
But I didn't understood it's logic.