this snippet calculates any timestamp into the weeks,days,hours and minutes that
passed since.
use it to show 'last updated' info or similar
“timestamp to time passed” makes use of the built-in PHP functions
time( ),
floor( ) and
filectime( ).
01 <?php
02
03 function time_passed($time)
04 {
05 $timestring = '';
06 $time = time()-$time;
07 $weeks = $time/604800;
08 $days = ($time%604800)/86400;
09 $hours = (($time%604800)%86400)/3600;
10 $minutes = ((($time%604800)%86400)%3600)/60;
11 $seconds = (((($time%604800)%86400)%3600)%60);
12 if(floor($weeks)) $timestring .= floor($weeks)." weeks ";
13 if(floor($days)) $timestring .= floor($days)." days ";
14 if(floor($hours)) $timestring .= floor($hours)." hours ";
15 if(floor($minutes)) $timestring .= floor($minutes)." minutes ";
16 if(!floor($minutes)&&!floor($hours)&&!floor($days)) $timestring .= floor($seconds)." seconds ";
17 return $timestring;
18 }
19
20 echo '
21 <p>';
22
23 // path to file - last update
24 // echo 'file example last updated '.time_passed(filectime('folder/folder/file')).' ago';
25
26 // this file - last update
27 echo 'this file last updated '.time_passed(filectime(__file__)).' ago';
28
29 // any timestamp - time passed
30 //echo time_passed(time()-(2*3600));
31
32 echo '
33 </p>';
34
35 ?>