Page 1 of 1

now - earlier time (simple?)

Posted: Fri Aug 13, 2010 6:19 am
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?

Re: now - earlier time (simple?)

Posted: Fri Aug 13, 2010 8:51 am
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";					
													}