born2dive Posted November 24, 2010 Share Posted November 24, 2010 I am a novice PHP coder, just started learning. I am trying to display a message on my webpage that should be triggered by a date check. The code is below (I removed all HTML tags for simplicity for now): <?php $m=date("m"); $d=date("d"); $y=date("Y"); $int_d = (int)$d; //Thanksgiving if ($m="11"&&$y="2010"&&$int_d>23&&$int_d<=28) { echo 'Happy Thanksgiving!'; } //Holidays if ($m="12"&&$y="2010"&&$int_d>=18&&$int_d<=31) { echo 'Happy Holidays!'; } ?> I want each statement to be executed during the appropriate dates i.e. "Happy Thanksgiving" from 11/24/2010 to 11/28/2010, and "Happy Holidays" from 12/18/2010 to 12/31/2010. The problem is that both statement are being executed regardless of the date conditions I use? Thoughts? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/219697-testing-for-dates-having-issues-with-my-test-conditions/ Share on other sites More sharing options...
mannyee Posted November 24, 2010 Share Posted November 24, 2010 your using the assignment operator '=' in your if condition, rather than making an equality comparison '==', you're assigning the values to the variables each time and each gets executed. change '=' to '==' Quote Link to comment https://forums.phpfreaks.com/topic/219697-testing-for-dates-having-issues-with-my-test-conditions/#findComment-1138950 Share on other sites More sharing options...
born2dive Posted November 24, 2010 Author Share Posted November 24, 2010 Thanks. That did it. Quote Link to comment https://forums.phpfreaks.com/topic/219697-testing-for-dates-having-issues-with-my-test-conditions/#findComment-1138967 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.