function age($birthday){ $now = time(); $dt=$now-$birthday; //let us check if current the date is far enought from birthday //(>2days), we can use simlified way to calculate age if( !((($dt+172800)%31557600)<345600) ){ $age=floor( $dt/31557600 ); }else{ $datestamp = date("d-m-Y", $now); list($current_day, $current_month,$current_year)= explode("-" , $datestamp); list($birth_year, $birth_month, $birth_day) = explode("-" , date('Y-m-d',$birthday)); $age = $current_year - $birth_year; if( ($birth_month > $current_month) || ($birth_month == $current_month && $current_day < $birth_day) ) $age--; } return $age; }