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? Link to comment https://forums.phpfreaks.com/topic/84215-solved-calculate-age/ 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 Link to comment https://forums.phpfreaks.com/topic/84215-solved-calculate-age/#findComment-428842 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() Link to comment https://forums.phpfreaks.com/topic/84215-solved-calculate-age/#findComment-428844 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 Link to comment https://forums.phpfreaks.com/topic/84215-solved-calculate-age/#findComment-428845 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; } ?> Link to comment https://forums.phpfreaks.com/topic/84215-solved-calculate-age/#findComment-428853 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.