Created
March 16, 2016 18:27
-
-
Save gustavo-s-rodrigues/b905513de1db6987ac7e to your computer and use it in GitHub Desktop.
Validate date from format
This file contains hidden or 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 | |
| /** | |
| * @param string $dateIn | |
| * @param string $format | |
| * @return bool | |
| */ | |
| function dateFormatValidate($dateIn = '', $format = 'Y-m') | |
| { | |
| try { | |
| $date = \DateTime::createFromFormat($format, $dateIn); | |
| if ($date->format($format) != $dateIn) { | |
| throw new \Exception('input date do not equal to your format'); | |
| } | |
| return true; | |
| } catch (\Exception $e) { | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment