It is probably faster to do something like:
function age($birthday) {
return date("Y", time() - strtotime($birthday)) - 1970;
}
It first converts the $birthday string to Unix Time. Which is the number of seconds since the epoch (midnight Jan 1 1970 UTC).
http://en.wikipedia.org/wiki/Unix_time
Then subtracts the birthday from the current unix time. This gives you the seconds elapsed between their birthday and today.
time() - strtotime($birthday)
Then retrieves the number years that would have elapsed in those seconds, since year 1970.
date("Y", time() - strtotime($birthday))
Then subtracts 1970 from that, to get the number years since birth (year 0).
Edit: limited to dates php can calculate with unix time.
Last edited by digital-ether; Jul 1st, 2009 at 7:50 am.
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
Offline 1,250 posts
since Sep 2005