note 30591 modified in function.time by chris

From: Date: Mon, 24 Mar 2003 10:48:02 +0000
Subject: note 30591 modified in function.time by chris
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-45729@lists.php.net to get a copy of this message
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. --was-- 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; $days=$time/144000; $hours=($time%144000)/6000; $minutes=(($time%144000)%6000)/100; $seconds=((($time%144000)%6000)%100); $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. http://www.php.net/manual/en/function.time.php

« previous php.notes (#45729) next »