Northern Flame Posted January 3, 2008 Share Posted January 3, 2008 Im having trouble calculating the birthdays of my users, when they register, they enter their date of birth in this format month: 01 day: 02 year: 1978 how can I calculate their age? Quote Link to comment Share on other sites More sharing options...
Barand Posted January 3, 2008 Share Posted January 3, 2008 You subtract the year they were born from this year to give age. If, however, the month/day of their birth has not yet been reached this year, subtract one from age Quote Link to comment Share on other sites More sharing options...
Mordax Praetorian Posted January 3, 2008 Share Posted January 3, 2008 I think this command may help you: getdate() Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted January 3, 2008 Author Share Posted January 3, 2008 thanks for the replies, ill take a look at getdate() and report back if it works fine for me Quote Link to comment Share on other sites More sharing options...
Barand Posted January 3, 2008 Share Posted January 3, 2008 getdate is a red herring. try <?php $yob = 1978; $mob = 1; $dob = 2; echo calcAge ($yob, $mob, $dob); // 30 function calcAge ($y,$m,$d) { $age = date('Y') - $y; return date('md') < sprintf('%02d%02d', $m, $d) ? $age-1 : $age; } ?> 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.