This is a very simple script that starts from a string date in format yyyy-mm-dd and return the age.
To do this it splits the date, calculate years with difference from current year and the fix the value based on difference between months and days from current date:
// input $date string format: YYYY-MM-DD function age($date){ list($year,$month,$day) = explode("-",$date); $year_diff = date("Y") - $year; $month_diff = date("m") - $month; $day_diff = date("d") - $day; if ($day_diff < 0 || $month_diff < 0) $year_diff--; return $year_diff; }
Easier Way to do this:
http://www.sudhirhub.com/2010/09/get-age-from-birthdate-using-php.html
age(“1994-04-27”);
I’m 16, but this function shows only 15 :D
Really? :D it needs a fix.
Nice :)