Skip to content

Instantly share code, notes, and snippets.

@ermand
Last active August 29, 2015 14:07
Show Gist options
  • Save ermand/aa6f4ae84074e8e9fb74 to your computer and use it in GitHub Desktop.
Save ermand/aa6f4ae84074e8e9fb74 to your computer and use it in GitHub Desktop.
Validate Age to be greater or equal to 18
<?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