Wednesday, June 2, 2010

Calculate the age from a DOB in one line

There are lots of complex ways to calculate someone's age from their DOB via PHP, but here's a simple one:
function getAge($dob) {
   return date("Y", time() - strtotime($dob)) - 1970;
}

echo getAge($dob);

No comments: