Jump to content

[SOLVED] inequality comparing two identical time strings?


bluesoul

Recommended Posts

$exp_date[$k] = date('Y-m-d',strtotime($exp_date[$k]));
$whois_exp_date[$k] = date('Y-m-d',strtotime($whois_exp_date[$k]));

 

Both results in this instance are 2009-08-02 yet when I run...

 

if ($exp_date[$k] == $whois_exp_date[$k])
			{ $sort[$k] = "match"; }

		if ($exp_date[$k] != $whois_exp_date[$k])
			{ $sort[$k] = "nomatch"; }

		else { $sort[$k] = "error"; }
echo $sort[$k]; // error

 

 

You're if statements are wrong. Try this:

 

if ($exp_date[$k] == $whois_exp_date[$k])
{ $sort[$k] = "match"; }
elseif ($exp_date[$k] != $whois_exp_date[$k])
{ $sort[$k] = "nomatch"; }

else { $sort[$k] = "error"; }

 

It should work. (note [ php] kills formatting when copy/pasting.)

The reason being is you used two if statements. The first one ran, than the second also ran, which of course the dates were equal so that if statement went to the else, thus overwriting the $sort[$k].

 

You set your self up to fail by doing that =), the elseif makes it all part of the same if so $sort[$k] does not get overwritten.

The reason being is you used two if statements. The first one ran, than the second also ran, which of course the dates were equal so that if statement went to the else, thus overwriting the $sort[$k].

 

You set your self up to fail by doing that =), the elseif makes it all part of the same if so $sort[$k] does not get overwritten.

 

Yup, that makes sense, it was set to match, then the second if statement executed, which failed and so went to the else.  Thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.