title: PHP calculate person's current age
body: <p>I have birth dates on my site in format <code>12.01.1980</code>.</p>
  
  <pre><code>$person_date (string) = Day.Month.Year
  </code></pre>
  
  <p>Want to add an oldness of the person. Like "<strong>Currently 30 years</strong>" (2010 - 1980 = 30 years).</p>
  
  <p>But makin the function just on years can't give the perfect result:</p>
  
  <p>If person birth date is <code>12.12.1980</code> and current date is <code>01.01.2010</code> the person doesn't have 30 years old. It's a 29 years and one month.</p>
  
  <p>There must be a calculation on targeting <strong>both year, month and day</strong> of birth with comparison of current date:</p>
  
  <p>0) Parse the dates.</p>
  
  <pre><code>Birth date (Day.Month.Year):
  Day = $birth_day;
  Month = $birth_month;
  Year = $birth_year;
  
  Current date (Day.Month.Year):
  Day = $current_day;
  Month = $current_month;
  Year = $current_year;
  </code></pre>
  
  <p>1) year comparison, 2010 - 1980 = write "30" (let it be <code>$total_year</code> variable)</p>
  
  <p>2) compare the months, if (birth date month is bigger > than current month (like 12 in birth and 01 current)) { do minus one year from <code>$total_year</code> variable (30 - 1 = 29) }. If do minus happened, finish the calculations at this point. Else go the next (3 step).</p>
  
  <p>3) <code>else if (birth month &lt; current month) { $total_year = $total_year (30); }</code></p>
  
  <p>4) <code>else if (birth month = current month) { $total_year = $total_year (30); }</code></p>
  
  <p>and check the day (in this step):</p>
  
  <pre><code> if(birth day = current day) { $total_year = $total_year; }
   else if (birth day &gt; current day) { $total_year = $total_year -1; }
   else if (birth day &lt; current day) { $total_year = $total_year; }
  </code></pre>
  
  <p>5) echo $total_year; </p>
  
  <p>My php knowledge isn't good, hope you can help.</p>
  
  <p>Thanks.</p>