Calculating Age in PHP, Update

If you remember, my goal was to write one line of PHP code that would calculate age from a birthday. My previous PHP age calculation code had me turning 25 three days early because I was not correcting for leap year. Oops! The corrected code is:

$age = floor((time() - strtotime($birthdate))/(60*60*24*365.2425));

I could use 365.24219 but 365.2425 only gives one day of error every 4,000 years. I can live with that.

Please see my original post, Calculating Age in PHP, for a full explanation of the code.


Add a Comment