title: PHP calculate age
body: <p>I'm looking for a way to calculate the age of a person, given their DOB in the format dd/mm/yyyy.</p>
  
  <p>I was using the following function which worked fine for several months until some kind of glitch  caused the while loop to never end and grind the entire site to a halt. Since there are almost 100,000 DOBs going through this function several times a day, it's hard to pin down what was causing this.</p>
  
  <p>Does anyone have a more reliable way of calculating the age?</p>
  
  <pre><code>//replace / with - so strtotime works
  $dob = strtotime(str_replace("/","-",$birthdayDate));       
  $tdate = time();
  
  $age = 0;
  while( $tdate &gt; $dob = strtotime('+1 year', $dob))
  {
      ++$age;
  }
  return $age;
  </code></pre>
  
  <p>EDIT: this function seems to work OK some of the time, but returns "40" for a DOB of 14/09/1986</p>
  
  <pre><code>return floor((time() - strtotime($birthdayDate))/31556926);
  </code></pre>