Jump to content

[SOLVED] inequality comparing two identical time strings?


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.