time - 5 minutes

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

time - 5 minutes

Post 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.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: time - 5 minutes

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: time - 5 minutes

Post 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"
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: time - 5 minutes

Post by Jonah Bron »

Oh wow, so PHP recognizes time built in?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: time - 5 minutes

Post by requinix »

No. It's just regular string comparison.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: time - 5 minutes

Post by Jonah Bron »

Oh, okay. I wasn't aware that PHP compared strings. :roll:
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

Re: time - 5 minutes

Post by IGGt »

wow, I didn't realise it was going to be so simple. cheers.
Post Reply