Checking the date entered by the user correct of not as according to a predefined format or not.
Example 1)
$format = 'd-m-Y';
$input = 'asasasawasa-sldjs';
$date = DateTime::createFromFormat($format, $input);
if($date)
echo 'The Date you entered is correct';
else
echo 'The date you entered is Incorrect';
OUTPUT: The Date you entered is incorrect
Example 2)
$format = 'd-m-Y';
$input = '09-12-2013';
$date = DateTime::createFromFormat($format, $input);
if($date)
echo 'The Date you entered is Correct';
else
echo 'The date you entered is Incorrect';
OUTPUT: The Date you entered is Correct
2 Comment(s)