Page 1 of 1

time - 5 minutes

Posted: Mon Nov 08, 2010 11:19 am
by IGGt
I can't quite seem to figure this out.

I have a time which represents a delay (along the lines of 00:05:13).

I then need to know if that delay is greater than 10 minutes.

what I have is:

Code: Select all

$network = $nw; //identifying name	
$d = $del['AvgDelay']; //avearge delay

		if 
			(time() - strtotime($d) > '600') {	
				print " <tr $colour1>\n";
				print "  <td>$network</td>\n  <td>$d</td>\n";
				print " </tr>\n";
		}elseif
			(time() - strtotime($d) > '320') {	
				print " <tr $colour3>\n";
				print "  <td>$network</td>\n  <td>$d</td>\n";
				print " </tr>\n";
		}else {
			print " <tr $colour2>\n";
			print "  <td>$network</td>\n  <td>$d</td>\n";
			print " </tr>\n";
			}
but this isn't working as no matter what the delay actually is (5 minutes, 1 minute etc.) it always seems to hit the first criteria (should be greater than 10 minutes). I'm guessing it's to do with the "strtotime($d)" query.

Re: time - 5 minutes

Posted: Mon Nov 08, 2010 11:30 am
by Jonah Bron
Insert this:

Code: Select all

echo $d . '<br>';
echo strtotime($d) . '<br>';
echo time() - strtotime($d);
Right after:

Code: Select all

$d = $del['AvgDelay']; //avearge delay

Re: time - 5 minutes

Posted: Mon Nov 08, 2010 11:38 am
by requinix
If the string is literally "00:05:13" (has hours, minutes, and seconds present with two digits for each) then you can just

Code: Select all

$d > "00:10:00"

Re: time - 5 minutes

Posted: Mon Nov 08, 2010 11:44 am
by Jonah Bron
Oh wow, so PHP recognizes time built in?

Re: time - 5 minutes

Posted: Mon Nov 08, 2010 12:15 pm
by requinix
No. It's just regular string comparison.

Re: time - 5 minutes

Posted: Mon Nov 08, 2010 12:26 pm
by Jonah Bron
Oh, okay. I wasn't aware that PHP compared strings. :roll:

Re: time - 5 minutes

Posted: Tue Nov 09, 2010 9:10 am
by IGGt
wow, I didn't realise it was going to be so simple. cheers.