Jump to content

funtion to return current age


bcamp1973

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.