jo.nova Posted September 29, 2006 Share Posted September 29, 2006 How would I write a function to check if someone is a certain age? They will be filling in a date of birth field, which I can check against today's date. But how do I implement it? Quote Link to comment Share on other sites More sharing options...
Barand Posted September 29, 2006 Share Posted September 29, 2006 Subtract the year of birth from this year to get age. However then check if month/day of birthdate has been reached this year, If not, subtract 1 from ageeg if born in 1990 thenthey will be 16 this year. But if birthday is November and it's now September then age is still 15. Quote Link to comment Share on other sites More sharing options...
printf Posted September 29, 2006 Share Posted September 29, 2006 A quick example... (you still need to validate the date!)[code=php:0]<?function get_age ( $m, $d, $y ){ $bd = date ( 'U', strtotime ( $m . '/'. $d . '/' . $y ) ); $yo = date ( 'Y', time () ) - date ( 'Y', $bd ); if ( date ( 'z', time () ) < date ( 'z', $bd ) ) { $yo -= 1; } return ( $yo );}$month = 10;$day = 28;$year = 1985;echo get_age ( $month, $day, $year ); ?>[/code]me! 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.