Skip to content

Instantly share code, notes, and snippets.

@sasin91
Created April 9, 2018 11:43
Show Gist options
  • Save sasin91/8f50b3cc721b5af20062e1b2768d43e2 to your computer and use it in GitHub Desktop.
Save sasin91/8f50b3cc721b5af20062e1b2768d43e2 to your computer and use it in GitHub Desktop.
Determine whether given input is a valid date or not
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