event happened x number of minutes ago

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zerodegreeburn
Forum Newbie
Posts: 24
Joined: Thu Jul 04, 2002 6:42 am
Contact:

event happened x number of minutes ago

Post 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?
Aaron
Forum Commoner
Posts: 82
Joined: Sun May 12, 2002 2:51 pm

Post 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';}}
Post Reply