bcamp1973 Posted April 8, 2007 Share Posted April 8, 2007 I was all proud of myself for getting this far with this function and then realized it's not returning the right values. It's purpose is to return the current age of an item based on it's date of creation. Can someone point me in the right direction? function age($startDate,$endDate=NULL){ $text=''; $seconds=strtotime($endDate!='0000-00-00 00:00:00' ? $endDate : gmdate('Y-m-d H:i:s'))-strtotime($startDate); $periods=array('yr'=>31570560,'mon'=>2630880,'day'=>86400,'hr'=>3600,'min'=>60); foreach($periods AS $k=>$v){ if(($temp=$seconds/$v)>=1){ $text.=floor($temp).' '.$k.($temp>=2 ? 's': '').' '; $seconds=$seconds % $v; } } return $text; } Link to comment https://forums.phpfreaks.com/topic/46143-funtion-to-return-current-age/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.