how could i calculate someones age from a normal date
F j, Y
thanks!
age question
Moderator: General Moderators
If you use a timestamp you will have trouble calc. dates before 1970.
Try this:
//Untested
Try this:
//Untested
Code: Select all
function getAge($_dob)
{
$a_ = dateToArray( $_dob );
//IS DATE A VALID DATE?
if(!is_array($a_) || !checkdate ( $a_['m'], $a_['d'], $a_['y'] ))
return FALSE;
$dob = $a_['y'].'-'.$a_['m'] .'-'.$a_['d'];
// calculate age
$age = date("Y-m-d")-$dob;
//has birthday happened this year?
if($a_['m'] > date("m") || ($a_['m'] == date("m") && $a_['d'] > date("d"))){
$age--;
}
return $age;
}