Barand Posted September 19, 2008 Share Posted September 19, 2008 Are you saying that if their age is 20 then you want to show the year of birth as 1972 ( = 1992 - 20)? Quote Link to comment https://forums.phpfreaks.com/topic/124557-solved-determining-birth-year/page/2/#findComment-645497 Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 Yes, Barand. I want the code to act like the current year is 1992. Quote Link to comment https://forums.phpfreaks.com/topic/124557-solved-determining-birth-year/page/2/#findComment-645749 Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 Or somehow set the date to March 23, 1992. Â Then take their age, and based on what month and day they put in the form, to figure out what year they were born. Like: Â If Serena was born on June 30 and is 13 Â then a calculation could be something like this: Â 1992-13 = 1979 June 30 is after March 23, so she has had her birthday this year (1992). Â But if Raye was born on March 17 and is 13 Â 1992 -13 = 1979 but since March 17 is BEFORE March 23, she has not had her birthday yet, and is her birthday year is actually 1978. Â Does that help at all? Quote Link to comment https://forums.phpfreaks.com/topic/124557-solved-determining-birth-year/page/2/#findComment-645875 Share on other sites More sharing options...
GingerRobot Posted September 20, 2008 Share Posted September 20, 2008 June 30 is after March 23, so she has had her birthday this year (1992). Â But if Raye was born on March 17 and is 13 Â 1992 -13 = 1979 but since March 17 is BEFORE March 23, she has not had her birthday yet, and is her birthday year is actually 1978. Â Surely that's completely the wrong way round? :s March 17 is before march 23 therefore, on march 23, she HAS had her birthday. And vise versa for the t'other example? Â Anywho, i'd do it like this: Â $age = 13; $mod = '03';//march - note that this must be a string and must be two digits $dob = '17'; $yob = ('0323' > $mod.$dob) ? 1992 - $age : 1992 - $age - 1; echo $yob; Quote Link to comment https://forums.phpfreaks.com/topic/124557-solved-determining-birth-year/page/2/#findComment-646246 Share on other sites More sharing options...
Barand Posted September 22, 2008 Share Posted September 22, 2008 Adjusting my previous code <?php function yearOfBirth ($day, $month, $age) { Â Â $now = strtotime('1992-03-23'); Â Â $yob = date('Y', $now) - $age; Â Â Â Â if (date('md', $now) < sprintf('%02d%02d', $month, $day)) $yob--; Â Â Â Â return $yob; } $year =Â yearOfBirth($_POST['birthdateday'], $_POST['birthdatemonth'], $_POST['age']); echo $year; ?> Quote Link to comment https://forums.phpfreaks.com/topic/124557-solved-determining-birth-year/page/2/#findComment-647522 Share on other sites More sharing options...
twilitegxa Posted July 20, 2009 Author Share Posted July 20, 2009 Barand, you code works perfectly! All I had to do was change the $yob-- to $age-- and it returns the correct value. :-) Thanks for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/124557-solved-determining-birth-year/page/2/#findComment-879091 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.