CalcAge





7
Date Submitted Fri. Nov. 17th, 2006 1:38 PM
Revision 1 of 1
Beginner twice
Tags "birthday"
Comments 2 comments
This Function simply calculate the age of a person or someting else and returns the age.

/*****************************************************************************************
* CalcAge
*
* 2006.09.22 - Eugen Tropmann
*
*
* Calc the Age
*
* Parameter:
* $birthday     = 1.9.1965
*****************************************************************************************/


function CalcAge($birthday){
   //Explode the Birthday and create the Array bDay.
   $bDay = explode(".",$birthday);
   //Create the Timestamp for now
   $now = mktime(0,0,0,date("m"),date("d"),date("Y"));
   //Create the Timestamp for the birthday
   $birthday = mktime(0,0,0,$bDay[1],$bDay[0],$bDay[2]);
   //Calc the age
   $age   = intval(($now - $birthday) / (3600 * 24 * 365));
   //Logic
   if(($age > 0) AND ($bDay[2] <= date("Y"))){
        return $age;
   }else{
        return false;
   }
}
 

Eugen Tropmann

Comments

Comments add PHP as a tag
Tue. Nov. 28th, 2006 4:20 PM    Scripter bertheymans
Comments Suggestion
Sat. Nov. 18th, 2006 3:34 AM    Helper Nico

Voting