Skip to content

Instantly share code, notes, and snippets.

@amitchhajer
Created December 28, 2012 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitchhajer/4395059 to your computer and use it in GitHub Desktop.
Save amitchhajer/4395059 to your computer and use it in GitHub Desktop.
Validating php date and date time
Validating a date from format yyyy-mm-dd
$date = DateTime::createFromFormat('Y-m-d', $generatedFrom);
if (!($date instanceof DateTime)) {
throw new ValidationError('Not valid start date');
}
Similarly other formats can be validated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment