Jump to content

Registration Age Query


graham23s

Recommended Posts

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

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.

$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

<?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']);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.