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 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 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. 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! 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. 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 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']); ?> 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, Link to comment https://forums.phpfreaks.com/topic/47815-registration-age-query/#findComment-233638 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.