Skip to content

Instantly share code, notes, and snippets.

@slav123
Created September 4, 2012 04:56
Show Gist options
  • Save slav123/3616737 to your computer and use it in GitHub Desktop.
Save slav123/3616737 to your computer and use it in GitHub Desktop.
calc age from date
/**
* age calculations based on date
*
* @param date $birth_date date in format Y-m-d
*
* @return bool|int
*/
function age($birth_date)
{
if (! preg_match('/\d{4}-\d{2}-\d{2}/', $birth_date)) {
$result_age = FALSE;
} else {
$result_age = DateTime::createFromFormat('Y-m-d', $birth_date)
->diff(new DateTime('now'))
->y;
}
return $result_age;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment