Seraskier Posted November 21, 2006 Share Posted November 21, 2006 Ok I have 3 tables, "birthday" "birthyear" and "birthmonth" and I was wondering how I can accuratly display someones age by doing the math from these three tables. Thanks. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 21, 2006 Share Posted November 21, 2006 Why on earth did you separate it into 3 tables? Quote Link to comment Share on other sites More sharing options...
Seraskier Posted November 21, 2006 Author Share Posted November 21, 2006 Well even if i add it all together, How would I do it. And also I can make it split apart and display on different parts of the website. So please help. Quote Link to comment Share on other sites More sharing options...
Seraskier Posted November 21, 2006 Author Share Posted November 21, 2006 **bump** Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 21, 2006 Share Posted November 21, 2006 Subtract the birth year from the current year. Then if the birth day hasn't happend this year, subtract 1.[code]<?php$currentYear = date("Y");$currentMonth = date("n");$currentDay = date("j");$birthday = 27;$birthmonth = 11;$birthyear = 1980;$age = $currentYear - $birthyear;$a = mktime(1,0,0,$currentDay, $currentMonth, $currentYear);$b = mktime(1,0,0,$birthday,$birthmonth,$currentYear);if ($a < $b){ $age--;}echo "<br />Current Month: " . $currentMonth;echo "<br />Current Day: " . $currentDay;echo "<br />Current Year: " . $currentYear;echo "<br/><br />Birth Month: " . $birthmonth;echo "<br />Birth Day: " . $birthday;echo "<br />Birth Year: " . $birthyear;echo "<br /><br />Age: " . $age;?>[/code] Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 21, 2006 Share Posted November 21, 2006 P.S. the 1, 0, 0 in the mktime function calls represent HOUR, MINUTE, SECOND. I'm just making sure we're looking at the same time of day on both the birthday and current day. That was also a little lengthy--I did it that way to make it easy to follow.It could be boiled down to this:[code]<?php$birthday = 27;$birthmonth = 11;$birthyear = 1980;$age = date("Y") - $birthyear;if (mktime(1,0,0,date("j"), date("n"), date("Y")) < mktime(1,0,0,$birthday,$birthmonth,date("Y"))){ $age--;}echo "<br /><br />Age: " . $age;?>[/code] Quote Link to comment 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.