Created
July 13, 2015 18:41
-
-
Save webkader/1230c8ce7f0a7432999c to your computer and use it in GitHub Desktop.
Check if a string is a valid date
This file contains 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 isValidDate($date, $format = "d-m-Y H:i:s") | |
{ | |
//since php 5.3 | |
$parsedate = date_parse_from_format($format, $date); | |
$datetmp = mktime($parsedate['hour'], $parsedate['minute'], $parsedate['second'], $parsedate['month'], $parsedate['day'], $parsedate['year']); | |
return (strtotime($date) == $datetmp) ? true : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment