Created
January 4, 2018 13:00
-
-
Save OkoyaUsman/125382de3ddf1d7e24a533a7f753f26d to your computer and use it in GitHub Desktop.
Calculate Age from Date of Birth in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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