now - earlier time (simple?)

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
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

now - earlier time (simple?)

Post by IGGt »

Is there an easy way to do something like:

CurrentTime - ReceivedTime (fromMySQL). I've seen plenty of long functions that people have created, but was hoping there might be something shorter and simpler.

I basically have a script which updates the database every 15 minutes (unless there's a problem), and was looking for some PHP that could subtract the time in the database from the current time, and display it as hh:mm:ss ( I would also need a way to filter it so I can change the colour, so maybe I need to be able to convert it to seconds as well).

I was hoping for something like:

$att = Time from Mysql
$now = Current Time from MySQL

if $now - $att > 15minutes {display hh:mm:ss in RED} else {display hh:mm:ss in Green}

Is this possible, or will I need a big function that I have to link to?
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

Re: now - earlier time (simple?)

Post by IGGt »

I've found it...

Code: Select all

while ($row = mysql_fetch_assoc($result)) {
				foreach ($row as $attribute)
						if (time() - strtotime($attribute) > '1200') {  				//20 minutes - RED
														print " <tr $colour1>\n"; } 
						elseif (time() - strtotime($attribute) > '960') {				//15 minutes - Orange
														print " <tr $colour3>\n"; }
						else { print " <tr $colour2>\n"; }	//Green															
						print "  <td>unit Name</td>\n";
						print "  <td>$attribute</td>\n </tr>\n";					
													}	
Post Reply