Last active
December 16, 2019 03:09
-
-
Save taner-dll/36b477ad714e072b0435 to your computer and use it in GitHub Desktop.
Symfony 2 - Validate 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
<?php | |
private function validateDate($date, $format = 'd-m-Y') | |
{ | |
$d = \DateTime::createFromFormat($format, $date); | |
return $d && $d->format($format) == $date; | |
} | |
if ($this->validateDate($dueDate) == true) { | |
$todo->setDueDate(\DateTime::createFromFormat('d-m-Y', $dueDate)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment