brown2005 Posted July 14, 2006 Share Posted July 14, 2006 function age($dob){$date = strtotime($dob);$today = strtotime(date("d/m/Y"));echo floor(($today - $date) / 31556926);}age("30/03/1983");i know floor rounds down the value but why the / 31556926 Quote Link to comment https://forums.phpfreaks.com/topic/14577-can-someone-help-explain-this/ Share on other sites More sharing options...
zq29 Posted July 14, 2006 Share Posted July 14, 2006 Ahhh, you took that from one of my replies earlier today! There are 31,556,926 seconds in a year - A Unix timestamp is the amount of seconds since the unix epoc (1st of January 1970 ish I think). Quote Link to comment https://forums.phpfreaks.com/topic/14577-can-someone-help-explain-this/#findComment-57851 Share on other sites More sharing options...
brown2005 Posted July 14, 2006 Author Share Posted July 14, 2006 wat about leap years though? Quote Link to comment https://forums.phpfreaks.com/topic/14577-can-someone-help-explain-this/#findComment-57852 Share on other sites More sharing options...
brown2005 Posted July 14, 2006 Author Share Posted July 14, 2006 semi u there Quote Link to comment https://forums.phpfreaks.com/topic/14577-can-someone-help-explain-this/#findComment-57858 Share on other sites More sharing options...
zq29 Posted July 14, 2006 Share Posted July 14, 2006 Sorry, went off to do a bit of research. I'm not 100% sure on this, but I don't think it matters...Seconds in a normal year: 3600 * 24 * 365 = 31,536,000Seconds in a leap year: 3600 * 24 * 366 = 31,622,400Seconds used in my function: 31,556,926 (Reported by Google - "seconds in a year")Maybe googles answer is some kind of average that accounts for the difference caused by leap years? I really don't know to be honest.Also, I've realised that my function won't work on all systems - negative timestamps are only supported in PHP5 and on *NIX based operating systems... Quote Link to comment https://forums.phpfreaks.com/topic/14577-can-someone-help-explain-this/#findComment-57859 Share on other sites More sharing options...
redarrow Posted July 14, 2006 Share Posted July 14, 2006 //my example playing with the timestamp.<?function redarrow($birthday){$d=date("d")+8;$m=date("m")+4;$y=date("y")+67;$my_birth_date=date("$d$m$y");$my_age=$y-42;$birthday=date("y")-31;$today_date=date("y-m-d");if($birthday < $today_date ) {echo " Your birthday was on the $my_birth_date I am $my_age years old ";} }redarrow($birthday);?> Quote Link to comment https://forums.phpfreaks.com/topic/14577-can-someone-help-explain-this/#findComment-57863 Share on other sites More sharing options...
GingerRobot Posted July 14, 2006 Share Posted July 14, 2006 mine:[code]<?php//all values must be without leading 0. Not sure why,lol$current_year = date("Y");$current_month = date("n");$current_day = date("j");$dob_day = 21;$dob_month = 9;$dob_year = 1989;$age = $current_year-$dob_year;if($dob_month >= $current_month){ $age--;}if($dob_month == $current_month && $dob_day >= $current_day){ $age++;}echo $age;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14577-can-someone-help-explain-this/#findComment-57864 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.