note 30591 deleted from function.time by aidan

From: Date: Sat, 08 Oct 2005 01:07:24 +0000
Subject: note 30591 deleted from function.time by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-96640@lists.php.net to get a copy of this message
Note Submitter: hamdiggy at robotskull dot com ---- this is probably already a function, but i thought i'd throw it in anyways. i just wrote this to show how long ago a folder on my server had been updated. here's the function: function thatDate($time){ $time=time()-$time; $weeks=$time/604800; $days=($time%604800)/86400; $hours=(($time%604800)%86400)/3600; $minutes=((($time%604800)%86400)%3600)/60; $seconds=(((($time%604800)%86400)%3600)%60); $timestring='last updated ['; if(round($days)) $timestring.=round($days)."d "; if(round($hours)) $timestring.=round($hours)."h "; if(round($minutes)) $timestring.=round($minutes)."m"; if(!round($minutes)&&!round($hours)&&!round($days)) $timestring.=" ".round($seconds)."s"; $timestring.=']'; return $timestring; } the argument it's looking for is the date the item was last changed. so you could call it with something like this echo thatDate(filectime('folder/folder/file')); and it will output something like "last updated [1d 13h 24m]". just make sure you give it a UNIX timestamp if you send it a time from a database or something. hope somebody finds this useful.

« previous php.notes (#96640) next »