Hi all, I need to calculate a members age and display it like- 34 ect. Problem - I have have the members - birth year in one column, birth month, in another and birth day in another, all in one table. for example- m_year m_month m_day How could I calculate their age to display like 34, 21 ect ! Do i compare it to todays date?
function birthday ($year, $month, $day) { $year_diff = date("Y") - $year; $month_diff = date("m") - $month; $day_diff = date("d") - $day; if ($month_diff < 0) $year_diff--; elseif (($month_diff==0) && ($day_diff < 0)) $year_diff--; return $year_diff; } echo birthday("1980","7","2"); ?> Code (markup):
function checkCurAge($year,$month,$day='') { $day=(empty($day))?'1':$day; list($this_year, $this_month, $this_day) = explode(' ',date('Y n j')); $age = $this_year - $year; if ($month>$this_month||($this_month==$month&&$this_day<$day)) { $age--; } return $age; }