Created
September 4, 2012 04:56
-
-
Save slav123/3616737 to your computer and use it in GitHub Desktop.
calc age from date
This file contains 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
/** | |
* 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