iom-7a
Last Updated: February 25, 2016
·
926
· ytilis

Age from DOB one-liner in PHP

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