age question
Posted: Sun Oct 02, 2005 9:40 am
how could i calculate someones age from a normal date
F j, Y
thanks!
F j, Y
thanks!
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
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;
}