PHP code calculate age based on date of birth

Many time we do face issue to calculate the date of birth using birthday date, therefore we have created following simple PHP script to calculate the age within few seconds only.

    $diff = (date('Y') - date('Y',strtotime($dob)));
    echo $diff;

Above script will show the output as per current date and year, for example today its 22nd Nov 2016, therefore above script output will be 27 years.

Senior technical writer

Be Sociable, Share!
About Anant 357 Articles
Senior technical writer