bluesoul Posted December 10, 2008 Share Posted December 10, 2008 $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 Quote Link to comment https://forums.phpfreaks.com/topic/136407-solved-inequality-comparing-two-identical-time-strings/ Share on other sites More sharing options...
premiso Posted December 10, 2008 Share Posted December 10, 2008 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.) Quote Link to comment https://forums.phpfreaks.com/topic/136407-solved-inequality-comparing-two-identical-time-strings/#findComment-711770 Share on other sites More sharing options...
bluesoul Posted December 10, 2008 Author Share Posted December 10, 2008 /blink I should stop coding when hungry. That's weird, though. I didn't expect an elseif to be the cause. Live and learn I suppose. Quote Link to comment https://forums.phpfreaks.com/topic/136407-solved-inequality-comparing-two-identical-time-strings/#findComment-711774 Share on other sites More sharing options...
premiso Posted December 10, 2008 Share Posted December 10, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/136407-solved-inequality-comparing-two-identical-time-strings/#findComment-711777 Share on other sites More sharing options...
bluesoul Posted December 10, 2008 Author Share Posted December 10, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/136407-solved-inequality-comparing-two-identical-time-strings/#findComment-711784 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.