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.

<?php
    $dob='1989-10-07';
    $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.

About Anant 384 Articles
Senior technical writer