Page 1 of 1

event happened x number of minutes ago

Posted: Thu Sep 04, 2003 2:47 pm
by zerodegreeburn
using a file last modified call in php would it be possible to work out the current time, then the modified time of the file in question, then calculate the difference in minutes between them?

Then, for example you could do, "Whatever was last accessed 3 minutes ago".

would be pretty cool :)

dunno how to do it though :S

any ideas?

Posted: Thu Sep 04, 2003 2:57 pm
by Aaron

Code: Select all

function TimeDiffo($time)
	{$uptime = time() - $time;
		$d = floor($uptime / 86400);
		$h = floor(($uptime % 86400) / (3600));
		$m = floor((($uptime % 86400) % 3600) / 60);
		$s = floor((($uptime % 86400) % 3600) % 60);
		
		if ($d)
		{return $d . "d $h" . 'h';}
		elseif ($h and !$d)
		{return $h . "h $m" . 'm';}
		elseif ($m and !$h and !$d)
		{return $m . "m $s" . 's';}
		elseif ($s and !$m and !$h and !$d)
		{return "$s" . 's';}}