liamloveslearning Posted May 23, 2010 Share Posted May 23, 2010 Hi everyone, im trying to calculate the age of a user using the following code... <?php function birthday ($row_getdets['dob']{ list($year,$month,$day) = explode("-",$birthday); $year_diff = date("Y") - $year; $month_diff = date("m") - $month; $day_diff = date("d") - $day; if ($day_diff < 0 || $month_diff < 0) $year_diff--; return $year_diff; } ?> My code seems to be breaking however and my page dies (outputs nothing) Can anybody see whats wrong? Is it my variable $row_getdets['dob']; Link to comment https://forums.phpfreaks.com/topic/202674-calculate-age/ Share on other sites More sharing options...
premiso Posted May 23, 2010 Share Posted May 23, 2010 birthday ($row_getdets['dob']); function birthday ($birthday){ Link to comment https://forums.phpfreaks.com/topic/202674-calculate-age/#findComment-1062336 Share on other sites More sharing options...
liamloveslearning Posted May 23, 2010 Author Share Posted May 23, 2010 thanks premiso, Ive just tried ... <?php $birthday = $row_getdets['dob']; function birthday ($birthday){ list($year,$month,$day) = explode("-",$birthday); $year_diff = date("Y") - $year; $month_diff = date("m") - $month; $day_diff = date("d") - $day; if ($day_diff < 0 || $month_diff < 0) $year_diff--; return $year_diff; } ?> to no avail, is this not what you meant? Link to comment https://forums.phpfreaks.com/topic/202674-calculate-age/#findComment-1062344 Share on other sites More sharing options...
marcus Posted May 23, 2010 Share Posted May 23, 2010 Now print it to the browser <?php echo birthday($birthday); ?> Link to comment https://forums.phpfreaks.com/topic/202674-calculate-age/#findComment-1062349 Share on other sites More sharing options...
liamloveslearning Posted May 23, 2010 Author Share Posted May 23, 2010 ahh thanks mgall! its printing 2010 however Link to comment https://forums.phpfreaks.com/topic/202674-calculate-age/#findComment-1062353 Share on other sites More sharing options...
liamloveslearning Posted May 23, 2010 Author Share Posted May 23, 2010 Sorry my bad! sorted Link to comment https://forums.phpfreaks.com/topic/202674-calculate-age/#findComment-1062354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.