Skip to content

Instantly share code, notes, and snippets.

@acfreitas
Last active August 29, 2015 14:10
Show Gist options
  • Save acfreitas/9c5b8ed4aaf9cb4354be to your computer and use it in GitHub Desktop.
Save acfreitas/9c5b8ed4aaf9cb4354be to your computer and use it in GitHub Desktop.
Check Date is valid
/**
* @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