graham23s Posted April 19, 2007 Share Posted April 19, 2007 Hi Guys, on my registration page users input there year,date and month of birth in 3 seperate drop down boxes say: [18] [June] [1979] i store each value in Mysql as birthday,birthmonth and birthyear what i was wanting to do is for PHP to work out this user is 27 years old and display age: 27 if you know what i mean not to sure how to acomplish this lol any help would be appreciated Graham Quote Link to comment https://forums.phpfreaks.com/topic/47815-registration-age-query/ Share on other sites More sharing options...
MadTechie Posted April 19, 2007 Share Posted April 19, 2007 please search the forum first Age calculation Quote Link to comment https://forums.phpfreaks.com/topic/47815-registration-age-query/#findComment-233614 Share on other sites More sharing options...
Glyde Posted April 19, 2007 Share Posted April 19, 2007 Here's a working example. <?php $result = array('birthday' => 10, 'birthmonth' => 10, 'birthyear' => 1990); $age = floor((time() - strtotime("{$result['birthday']}/{$result['birthmonth']}/{$result['birthyear']}")) / (365 * 24 * 60 * 60)); print $age; ?> Simple and effective. Quote Link to comment https://forums.phpfreaks.com/topic/47815-registration-age-query/#findComment-233617 Share on other sites More sharing options...
MadTechie Posted April 19, 2007 Share Posted April 19, 2007 doesn't work 100%, doesn't take months into account, ie if the month is the 4 and your birth month is the 7 then it will still count as if you had your birthday that year! Quote Link to comment https://forums.phpfreaks.com/topic/47815-registration-age-query/#findComment-233622 Share on other sites More sharing options...
Glyde Posted April 19, 2007 Share Posted April 19, 2007 doesn't work 100%, doesn't take months into account, ie if the month is the 4 and your birth month is the 7 then it will still count as if you had your birthday that year! Just tested it and it worked as it should. With 10/10/90 in there it showed an age of 16...According to what you said it should print 17. Quote Link to comment https://forums.phpfreaks.com/topic/47815-registration-age-query/#findComment-233625 Share on other sites More sharing options...
MadTechie Posted April 19, 2007 Share Posted April 19, 2007 $result = array('birthday' => 01, 'birthmonth' => 03, 'birthyear' => 1990); returns 17 $result = array('birthday' => 01, 'birthmonth' => 05, 'birthyear' => 1990); returns 17 the current Month is the 4 so on the 3rd month it should be 16 and on the 5th month it should be 17 Quote Link to comment https://forums.phpfreaks.com/topic/47815-registration-age-query/#findComment-233629 Share on other sites More sharing options...
Glyde Posted April 19, 2007 Share Posted April 19, 2007 <?php function currentAge($birthday, $birthmonth, $birthyear) { $dateParts = explode("-", date("m-d-Y")); $birthDate = gregoriantojd($birthmonth, $birthday, $birthyear); $todayDate = gregoriantojd($dateParts[0], $dateParts[1], $dateParts[2]); return ($todayDate - $birthDate) / 365; } $result = array('birthday' => 1, 'birthmonth' => 04, 'birthyear' => 1990); print currentAge($result['birthday'], $result['birthmonth'], $result['birthyear']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/47815-registration-age-query/#findComment-233637 Share on other sites More sharing options...
MadTechie Posted April 19, 2007 Share Posted April 19, 2007 Doesn't work Just kidding looks like it will work, Quote Link to comment https://forums.phpfreaks.com/topic/47815-registration-age-query/#findComment-233638 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.