Last active
August 29, 2015 14:07
-
-
Save ermand/aa6f4ae84074e8e9fb74 to your computer and use it in GitHub Desktop.
Validate Age to be greater or equal to 18
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 Age to be greater or equal to 18 | |
* | |
* @param $birthdate | |
* @return boolean | |
*/ | |
function validateAge($birthdate) | |
{ | |
$currentDate = new DateTime("now"); | |
$birthdate = new DateTime($birthdate); | |
$interval = date_diff($currentDate, $birthdate); | |
// var_dump($interval->y); | |
if ($interval->y >= 18) | |
return true; | |
else | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment