Reputation: 58301
I have 3 variables $day, $month, $year each of them have the values what the users given to them.
I want to get his real Age too from these 3 variables.
For example the user enters this date for his birthdate in this format day,month,year:
04, 07, 1990 -> Now his age is 19
02, 07, 1990 -> Now his age is 20
I want to have it in this way.
I hope it's clear.
Upvotes: 0
Views: 1712
Reputation: 16439
Could use something like this:
function age($bMonth,$bDay,$bYear) {
list($cYear, $cMonth, $cDay) = explode("-", date("Y-m-d"));
return ( ($cMonth >= $bMonth && $cDay >= $bDay) || ($cMonth > $bMonth) ) ? $cYear - $bYear : $cYear - $bYear - 1;
}
Upvotes: 2