communication
 databases
 directories
 file handling
 html and code
 image editing
 image listing
 sessions and co
 string handling
 information
 forms
 apple stuff
 image handling
 array handling
 lixlpixel
php - snippets
google search terms detected and highlighted.
remove highlighting | keep highlighting
make snippet in "information" - download "timestamp to time passed" - open demo of "timestamp to time passed"
 search
php - snippets

Valid CSS!

php webring logo
prev next
random list
join the Ring!

information - timestamp to time passed was created/last modified on Sun 18 Apr 2004 9:53 AM

this snippet calculates any timestamp into the weeks,days,hours and minutes that passed since.
  
use it to show 'last updated' info or similar
  
<?php
  
function time_passed($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);
   if(
round($weeks)) $timestring = round($weeks)." weeks ";
   if(
round($days)) $timestring .= round($days)." days ";
   if(
round($hours)) $timestring .= round($hours)." hours ";
   if(
round($minutes)) $timestring .= round($minutes)." minutes ";
   if(!
round($minutes)&&!round($hours)&&!round($days)) $timestring .= round($seconds)." seconds ";
   return
$timestring;
}
  
//echo 'file example last updated '.time_passed(filectime('folder/folder/file')).' ago'; // path to file - last update
echo 'this file last updated '.time_passed(filectime(__file__)).' ago'; // this file - last update
//echo time_passed(time()-(2*3600)); // any timestamp - time passed
  
?>

learn more about some of the PHP functions used in this snippet: date, echo, file, filectime, function, min, return, round, time

view the GNU general license - view the GNU library license - search on PHPsnippets - see your code like this

 a lixlpixel.com site

PHParadise.com - PHP-classes.org - your site on safari