Skip to content

Instantly share code, notes, and snippets.

@weird-coon
Last active June 8, 2018 03:46
Show Gist options
  • Save weird-coon/24974401de632d9c47349b079592eb07 to your computer and use it in GitHub Desktop.
Save weird-coon/24974401de632d9c47349b079592eb07 to your computer and use it in GitHub Desktop.
[PHP] Validate date PHP function with date format. Return true if valid date and other side.
<?php
/**
* Valid datetime format
*
* @param string $date
* @param string $format
* @return bool
*/
private function validate_date($date, $format = 'Y/m/d')
{
$d = DateTime::createFromFormat($format, $date);
return $d && $d->format($format) === $date;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment