James.Cridland.net

Age calculator

James's first rule of website maintenance: always make the server do the work, not you. So, if you put your age on your homepage, make sure you don't need to update it.

My birthday is the 18th March 1971: you'll need to change those numbers in the code below.

<?
// I was born in 1971
$age= (date("Y") - 1971);
// On 18/3 (18th March for any US people looking)
if((date("n") < 3) or (date("n") == 3 and date("j") < 18)) {
    
$age--;
}
// Echo the age
echo $age;
?>

Download this code

Er - this is Duncan's code. Mine, which used to be here, was a bit buggy.