Calculating Age with PHP

You would think that determining a person's age would be a very simple task for a PHP developer.  However, when I asked this question for myself I found a variety of solutions that people posted online.  Many of them used large functions with conditionals and other logic that was hard to follow.  After a significant amount of research, I've come to find the shortest and most accurate solution to this question.

function current_age($birthdate) {
    return( floor((time()-strtotime($birthdate))/31536000) );
}

You can pass just about any type date that strtotime() can recognize, which is an added convenience.  If you have a better solution, let's hear about it in the comments.

Author avatar

About the author

New Hampshirite building web apps in Florida. Creator of Surreal CMS, Postleaf, and DirtyMarkup.

Need to get in touch? Catch me on Twitter.