| AND OR | string words | *

information

|

timestamp to time passed

| see demonstration of timestamp to time passed


this snippet calculates any timestamp into the weeks,days,hours and minutes that passed since.

use it to show 'last updated' info or similar


function time_passed( ) [ line 2 ]



full source of timestamp to time passed [ line 1 - 20 ] | download timestamp to time passed

1    <?php
2   function time_passed($time)
3   {
4     $time time()-$time;
5     $weeks $time/604800;
6     $days = ($time%604800)/86400;
7     $hours = (($time%604800)%86400)/3600;
8     $minutes = ((($time%604800)%86400)%3600)/60;
9     $seconds = (((($time%604800)%86400)%3600)%60);
10     if(round($weeks)) $timestring round($weeks)." weeks ";
11     if(round($days)) $timestring .= round($days)." days ";
12     if(round($hours)) $timestring .= round($hours)." hours ";
13     if(round($minutes)) $timestring .= round($minutes)." minutes ";
14     if(!round($minutes)&&!round($hours)&&!round($days)) $timestring .= round($seconds)." seconds ";
15     return $timestring;
16   }
17   //echo 'file example last updated '.time_passed(filectime('folder/folder/file')).' ago'; // path to file - last update
18   echo 'this file last updated '.time_passed(filectime(__file__)).' ago'// this file - last update
19   //echo time_passed(time()-(2*3600)); // any timestamp - time passed
20   ?>



29 hits by 18 users in the last 30 minutes.