PHP – Calculate Age

The given PHP example can calculate the age in years. The age format should be mounth-day-year.

Code Example:
function getAge($date){ # mounth-day-year
$bday = explode("-", $date, 3);
$bday = mktime(0,0,0,$bday[0],$bday[1],$bday[2]);
$age = (int)((time()-$bday)/31556926 );
return $age;

echo getAge("08-08-2008"); # returns the age.

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *