Skip to content

Instantly share code, notes, and snippets.

@OkoyaUsman
Created January 4, 2018 13:00
Show Gist options
  • Save OkoyaUsman/125382de3ddf1d7e24a533a7f753f26d to your computer and use it in GitHub Desktop.
Save OkoyaUsman/125382de3ddf1d7e24a533a7f753f26d to your computer and use it in GitHub Desktop.
Calculate Age from Date of Birth in PHP
<?php
function getAge($dob) {
$today = date("Y-m-d");
$diff = date_diff(date_create($dob), date_create($today));
return $diff->format('%yYears, %mMonths, %dDays');
}
// You can add the above function in your php library and use any where to calculate the age of the user by their date of birth.
echo getAge('19-10-1988');
// Output: 27Years, 10Months, 19Days
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment