Last active
June 8, 2018 03:46
-
-
Save weird-coon/24974401de632d9c47349b079592eb07 to your computer and use it in GitHub Desktop.
[PHP] Validate date PHP function with date format. Return true if valid date and other side.
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
<?php | |
/** | |
* Valid datetime format | |
* | |
* @param string $date | |
* @param string $format | |
* @return bool | |
*/ | |
private function validate_date($date, $format = 'Y/m/d') | |
{ | |
$d = DateTime::createFromFormat($format, $date); | |
return $d && $d->format($format) === $date; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment