Skip to content

Instantly share code, notes, and snippets.

@gustavo-s-rodrigues
Created March 16, 2016 18:27
Show Gist options
  • Select an option

  • Save gustavo-s-rodrigues/b905513de1db6987ac7e to your computer and use it in GitHub Desktop.

Select an option

Save gustavo-s-rodrigues/b905513de1db6987ac7e to your computer and use it in GitHub Desktop.
Validate date from format
<?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