title: Calculate age from birthdate in PHP
body: <p>A friend of mine gave me this code, but I can't seem to get it to work. It keeps telling me that I have an undefined variable, but I have tried to define it several different ways, but it doesn't show their right age, it shows everyone as 43. Here is the code I'm using:</p>
  
  <pre><code>$bdate= getdate('$_GET["bd"]');
  
  if($bdate == 0){ $nodate = 1; }
  $bdate = strtotime( $bdate );
  $birthday = date("n/j/Y",$bdate);  //must be as m/d/yyyy
  
  $bday = explode("/", $birthday); //parse
  $b_mm = $bday[0]; //birthday month
  $b_dd = $bday[1]; //birthday day
  $b_yyyy = $bday[2]; //birthday year
  
  //compare timestamps of mm/dd for birthday and today
  $bday_mm_dd = mktime(0,0,0,$b_mm,$b_dd,0);
  $today_mm_dd = mktime(0,0,0,date("m"),date("d"),0);
  $age = date("Y", time()) - $b_yyyy;
  
  if ($bday_mm_dd &gt; $today_mm_dd) {
  //birthday hasnt happened yet this year
  $age = $age - 1;
  }
  </code></pre>
  
  <p>Just for clarification in my sql statement I have the birthdate listed as bd.</p>
  
  <p>If anyone can help, I would greatly appreciate it.</p>