Warning: The article below is over five years old. It may be badly written, poorly considered, immature, obsolete, no longer my opinion, or simply flat-out wrong.

A PHP snippet to calculate your age

MyAge is a code snippet that calculates your age. I hadn't bothered posting it, as it's fairly trivial, but someone asked for it in an IRC channel last night so I thought it might be more useful to people than I realised.

<?php /** * MyAge by Alex Pounds <> * A small script to calculate my age, instead of updating a webpage once a year. */ // Edit the numbers below to match your birthdate. $birthyear=1982; $birthmonth=4; $birthday=23; $nowyear=date("Y"); $nowmonth=date("m"); $nowday=date("d"); if($nowmonth > $birthmonth) { //Age is simply the difference in years. print $nowyear - $birthyear; return; } else if($nowmonth == $birthmonth) { if($nowday < $birthday) { print $nowyear - $birthyear - 1; return; } else { print $nowyear - $birthyear; return; } } else { print $nowyear - $birthyear - 1; return; } ?>