1 2 3 4 5
<?php function getAge($birthdate) { return floor((time() - strtotime($birthdate))/(60*60*24*365.2425)); } ?>
Refactorings
No refactoring yet !
Alix Axel
May 3, 2010, May 03, 2010 00:26, permalink
This computes the age in a non-mathematical way and thus is not subject to imprecisions caused by leap years. This is the way we (humans) celebrate birthdays, not how many (60*60*24*365.2425) seconds have passed since we were born.
1 2 3 4 5 6 7
<?php function getAge($birthdate) { return intval(substr(date('Ymd') - date('Ymd', strtotime($birthdate)), 0, -4)); } ?>
How to get age from given birthdate