Sometime we need to check that date is valid or not, In many website input filed is date time so input date is valid or not need to check this. You can do this using php createFromFormat. This is simple demo code.

<?php
function validateDate($date, $format = 'Y-m-d H:i:s')
{
    $d = DateTime::createFromFormat($format, $date);
    return $d && $d->format($format) == $date;
}

echo '2018-04-27 12:12:12'.var_dump(validateDate('2018-04-27 12:12:12')); # true
echo '2018-04-32 12:12:12'.var_dump(validateDate('2018-04-32 12:12:12')); # false
echo '2018-04-30 12:12:61'.var_dump(validateDate('2018-04-30 12:12:61')); # false

Then Output is :

2018-04-27 12:12:12 : boolean true
2018-04-32 12:12:12 : boolean false
2018-04-30 12:12:61 : boolean false

You can also check date , this is demo code

<?php
function validateDate($date, $format = 'Y-m-d')
{
    $d = DateTime::createFromFormat($format, $date);
    return $d && $d->format($format) == $date;
}

echo '2018-04-27'.var_dump(validateDate('2018-04-27')); # true
echo '2018-04-32'.var_dump(validateDate('2018-04-32')); # false
echo '2018-04-30'.var_dump(validateDate('2018-04-30')); # false

Then Output is :

2018-04-27 : boolean true
2018-04-32 : boolean false
2018-04-30 : boolean true

If you face nay problem then please inform me. I will try to help you