Skip to content

Instantly share code, notes, and snippets.

@taner-dll
Last active December 16, 2019 03:09
Show Gist options
  • Save taner-dll/36b477ad714e072b0435 to your computer and use it in GitHub Desktop.
Save taner-dll/36b477ad714e072b0435 to your computer and use it in GitHub Desktop.
Symfony 2 - Validate Date
<?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