So many time we need to calculate user age from date of birth of the user. Here I'm giving an example code in PHP. I have written a function getAge() and you just need to pass the date of birth of the user in a given format. You will get the age of the user.
1
2
3
4
5
6
7
8
9
|
<?php
function getAge($dob) {
$today = date("Y-m-d");
$diff = date_diff(date_create($dob), date_create($today));
return $diff->format('%yYears, %mMonths, %dDays');
}
echo getAge('20-11-1990');
?>
|