Last active
August 29, 2015 14:10
-
-
Save acfreitas/9c5b8ed4aaf9cb4354be to your computer and use it in GitHub Desktop.
Check Date is valid
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
/** | |
* @param string $date | |
* @param string $format | |
* @return boolean | |
*/ | |
public function isValidDate($date, $format = 'dd.mm.yyyy') { | |
if (strlen($date) >= 6 && strlen($format) == 10) { | |
// find separator. Remove all other characters from $format | |
$separator_only = str_replace(array('m', 'd', 'y'), '', $format); | |
$separator = $separator_only[0]; // separator is first character | |
if ($separator) { | |
$arr = explode($separator, $date); | |
$day = $arr[0]; | |
$month = $arr[1]; | |
$year = $arr[2]; | |
if (checkdate($month, $day, $year)) | |
return true; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment