Created
April 9, 2018 11:43
-
-
Save sasin91/8f50b3cc721b5af20062e1b2768d43e2 to your computer and use it in GitHub Desktop.
Determine whether given input is a valid date or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function is_date($value): bool | |
{ | |
if ($value instanceof DateTime) { | |
return true; | |
} | |
if ((! is_string($value) && ! is_numeric($value)) || strtotime($value) === false) { | |
return false; | |
} | |
$date = date_parse($value); | |
return checkdate($date['month'], $date['day'], $date['year']); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment