Home > Article > Backend Development > Calculate age based on date of birth (taking into account leap years)
Mainly considering the situation of leap years, if someone is born on 2.29, then if it is not a leap year, then 2.28 will be counted as one year old.
OnFunction Age ($ BIRTH) { $ Age = Array (); // $ now = date ('ymd'); $ now = "20110228"; $nowyear = (int) ($now / 10000); $nowmonth = (int) (($now % 10000) / 100); //Decompose the date of birth into Year, month and day
$birthyear = (int) ($birth / 10000);
|