illusiveone Posted January 30, 2008 Share Posted January 30, 2008 hi everyone im trying to get this age property in my website to work properly, and the way it stands right now.. the age is being determined by the year and not by the specific date and month that the user supplies. which isnt a big problem, but its annoying.here is the code that is being used atm. <?php $dbt=$data['dob']; $dbt2=explode('-',$dbt); //print_r($dbt2); $m=$dbt2[0]; $d=$dbt2[1]; $y=$dbt2[2]; $st=mktime(0,0,0,$m,$d,$y); $st1=date("F d, Y ",$st); $date1=date("m, d, Y"); $year=$date1-$y; ?> i havent used an age calculator such as this before, so im not too sure of myself when it comes to this. it also doesnt help that it was written by someone else. any and all help would be greatly appreciated, thank you in advance! Quote Link to comment https://forums.phpfreaks.com/topic/88644-users-age-isnt-working-right/ Share on other sites More sharing options...
The Little Guy Posted January 30, 2008 Share Posted January 30, 2008 http://phpsnips.com/snippet.php?id=7 Quote Link to comment https://forums.phpfreaks.com/topic/88644-users-age-isnt-working-right/#findComment-453922 Share on other sites More sharing options...
Barand Posted January 30, 2008 Share Posted January 30, 2008 It's a simple calculation. age = year now minus year born. If the day/month of birth hasn't been reached yet this year then subtract 1 from age. <?php $dob = '1949-01-22'; echo age($dob); function age($dob) { $tob = strtotime($dob); $age = date('Y') - date('Y', $tob); return date('md') < date('md', $tob) ? $age-1 : $age; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/88644-users-age-isnt-working-right/#findComment-453934 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.