<p>Such things like copyright dates, ages, etc. can cause problems on websites unless they are dynamic. For example, I have my age in the little about me blurb in the sidebar. I made a little function to calculate my age so that I don’t have to go in every year on my birthday and add another year to my age.</p>



<h2 class="replaceHeadline">The Function</h2>
<div class="codeblock"><code>
function age($bMonth,$bDay,$bYear) {<br /> <br /> $cMonth = date('n');<br /> $cDay = date('j');<br /> $cYear = date('Y');<br /><br /> if(($cMonth &gt;= $bMonth &amp;&amp; $cDay &gt;= $bDay) || ($cMonth &gt; $bMonth)) {<br />  return ($cYear - $bYear);<br /> } else {<br />  return ($cYear - $bYear - 1);<br /> }<br />} 

</code></div>

<p>This function takes 3 arguments: the birth month, the birth day, and the birth year. It will return the calculated age. It obviously won’t work with an age in the future; it will return a negative number. I could add in checking to see if it’s a valid date, but I don’t think it’s really necessary.</p>

<p><a href="//trevor-davis.com/play/php-get-age-function-examples/">Check Out Some Examples</a></p>

<p>Nothing too complicated. Let me know if anyone has any suggestions to shorten the code.</p>