Most easiest way to find age (years/month)
now use it echo return_age('2010-02-01');
function return_age($dob){
$from = new DateTime($dob);
$to = new DateTime('today');
if( $from->diff($to)->y!=0){
echo $from->diff($to)->y." Years";
}
else{
echo $from->diff($to)->m." Months";
}
}
now use it echo return_age('2010-02-01');
if age less than one year then it'll show month like 9 Months.
No comments:
Post a Comment