Last Updated: February 25, 2016
·
1.035K
· ytilis

Age from DOB one-liner in PHP

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);