xyn Posted July 14, 2006 Share Posted July 14, 2006 Hi,I was wondering how to get a date of birth from a database and calculate it/the year to output an age.ie: 01/02/1990 - 16 | 01/02/1989 - 17.but make PHP calculate it. Quote Link to comment https://forums.phpfreaks.com/topic/14569-dob-calculations/ Share on other sites More sharing options...
zq29 Posted July 14, 2006 Share Posted July 14, 2006 I might have gone at this the long way around, but hey, it works...[code]<?phpfunction age($dob) { $date = strtotime($dob); $today = strtotime(date("d/m/Y")); echo floor(($today - $date) / 31556926);}age("16/12/1985"); //Displays 20?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14569-dob-calculations/#findComment-57810 Share on other sites More sharing options...
xyn Posted July 14, 2006 Author Share Posted July 14, 2006 thanks :] if it works it doesn't matter how long it is really. Quote Link to comment https://forums.phpfreaks.com/topic/14569-dob-calculations/#findComment-57813 Share on other sites More sharing options...
brown2005 Posted July 14, 2006 Share Posted July 14, 2006 yes thanks, i need that code.. very nifty Quote Link to comment https://forums.phpfreaks.com/topic/14569-dob-calculations/#findComment-57814 Share on other sites More sharing options...
zq29 Posted July 14, 2006 Share Posted July 14, 2006 Looking back on my solution, it's not a very good one, as unix time stamps only start from 01/01/1970 and Negative timestamps are only available on PHP5 and on some *NIX based OS Quote Link to comment https://forums.phpfreaks.com/topic/14569-dob-calculations/#findComment-57856 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.