Last active
June 11, 2019 16:41
-
-
Save lenivene/b19dc9f7c22b3b63b290321db77bc19e to your computer and use it in GitHub Desktop.
Function PHP - Validate Date, returns TRUE if the date given is valid; otherwise returns FALSE.
This file contains hidden or 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 | |
/** | |
* Validate Date | |
* | |
* @return boolean Returns TRUE if the date given is valid; otherwise returns FALSE. | |
*/ | |
function is_date_valid( $date, $format = 'Y-m-d H:i:s'){ | |
if( ! isset( $date ) || isset( $date ) && ! is_string( $date ) ) | |
return false; | |
$date_time = DateTime::createFromFormat( $format, $date ); | |
$is_invalid = (bool) ( $date_time && $date_time->format( $format ) == $date ); | |
return $is_invalid; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment