SciFiSi Posted July 5, 2013 Share Posted July 5, 2013 This should be the easiest thing in the world, but it just does not and WILL not work. I've spent hours and hours on this and I just do NOT understand what's wrong with this code can someone - anyone please please help and explain what I'm doing wrong!?$hour = date('G');echo "$hour ";if ($hour >= 0 && $hour <= 11){ echo 'Good morning ';}else if ($hour >=12 && $hour <=17){ echo 'Good afternoon ';}else ($hour >=18){ echo 'Good evening ';}All it ever prints out is Good evening! WTF! Quote Link to comment Share on other sites More sharing options...
_EmilsM Posted July 5, 2013 Share Posted July 5, 2013 (edited) <?php $hour = date('G'); echo "$hour "; if ($hour >= 0 && $hour <= 11) { echo 'Good morning '; } else if ($hour >=12 && $hour <=17) { echo 'Good afternoon '; } else if($hour >=18 && $hour<= 24) { echo 'Good evening '; } ?> using this, prints good afternoon. EDIT. Maybe because $hour is now 18 to 24 for you. Define $hour for yourself, try 0, 11, 12, 17 and you'll see that it changes. Edited July 5, 2013 by _EmilsM Quote Link to comment Share on other sites More sharing options...
SciFiSi Posted July 5, 2013 Author Share Posted July 5, 2013 Sorry, I can't see any difference - did you change the code in any way? Quote Link to comment Share on other sites More sharing options...
Solution _EmilsM Posted July 5, 2013 Solution Share Posted July 5, 2013 Only thing i did was added else if instead of else, but yea, it works perfetly for me. Maybe because $hour is now 18 to 24 for you. Define $hour for yourself, try 0, 11, 12, 17 and you'll see that it changes. Quote Link to comment Share on other sites More sharing options...
SciFiSi Posted July 5, 2013 Author Share Posted July 5, 2013 Ah, yes I see you added the <=24. I've copied and pasted your code and now I don't get any output at all. What is probably VERY worth mentioning is that I'm using a plugin for Wordpress ; http://wordpress.org/plugins/allow-php-in-posts-and-pages/ It's very possible that this plugin just doesn't work and if that's the case I'll be peeved. . Quote Link to comment Share on other sites More sharing options...
SciFiSi Posted July 5, 2013 Author Share Posted July 5, 2013 (edited) Thanks for taking a look at that for me, at least I've proven it's not me going mad and it's the fault of that stupid plugin! Edited July 5, 2013 by SciFiSi Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted July 5, 2013 Share Posted July 5, 2013 On a side note the max value for hour if you are using a less than or equal to operator is 23 not 24. In a 24 hour clock 23:00 + 1 hour is 00:00. Just being picky. Quote Link to comment Share on other sites More sharing options...
litebearer Posted July 5, 2013 Share Posted July 5, 2013 Might consider using SWITCH ( <12, <18, Default would cover 6pm to midnight Quote Link to comment 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.