I've noticed a couple different post addressing age calculation..
here is a simple function I wrote to address the issue:
//--------------------------------------------------
// Age Calculation Function
function ageYearsCalculate($birthday) {
global $ageYears;
$rightNow = date("Ymd");
$ageYears = $rightNow - $birthday;
$ageYears = substr($ageYears, 0, 2);
return($ageYears);
}
Example:
Birthday = 19850612
Today = 20050122
20050122 - 19850612 = 199510
age = substr(199510, 0, 2);
age = 19
20050611 - 19850612 = 199999
20050612 - 19850612 = 200000
20050613 - 19850612 = 200001
Does this seem to make sense?
Can anyone find a fault in this function? It seems to work fine for me, and since its raw math, epoch is not a concern... So birthdays before 1970 work fine as well. The only limitation in the way I have this set up would be people older than 100, but since my form only allows someone to choose a birthday within the last 98 years, it works fine.
A couple previous posts on the subject:
http://phpbuilder.com/board/showthread.php?threadid=10273394&highlight=age+calculation
http://www.phpbuilder.com/board/showthread.php?s=&threadid=10253351&highlight=age#post10410290