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! Link to comment https://forums.phpfreaks.com/topic/279893-the-easiest-code-in-the-world-and-yet-it-doesnt-work-wtf/ Share on other sites More sharing options...
_EmilsM Posted July 5, 2013 Share Posted July 5, 2013 <?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. Link to comment https://forums.phpfreaks.com/topic/279893-the-easiest-code-in-the-world-and-yet-it-doesnt-work-wtf/#findComment-1439529 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? Link to comment https://forums.phpfreaks.com/topic/279893-the-easiest-code-in-the-world-and-yet-it-doesnt-work-wtf/#findComment-1439530 Share on other sites More sharing options...
_EmilsM Posted July 5, 2013 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. Link to comment https://forums.phpfreaks.com/topic/279893-the-easiest-code-in-the-world-and-yet-it-doesnt-work-wtf/#findComment-1439532 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. . Link to comment https://forums.phpfreaks.com/topic/279893-the-easiest-code-in-the-world-and-yet-it-doesnt-work-wtf/#findComment-1439535 Share on other sites More sharing options...
SciFiSi Posted July 5, 2013 Author Share Posted July 5, 2013 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! Link to comment https://forums.phpfreaks.com/topic/279893-the-easiest-code-in-the-world-and-yet-it-doesnt-work-wtf/#findComment-1439538 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. Link to comment https://forums.phpfreaks.com/topic/279893-the-easiest-code-in-the-world-and-yet-it-doesnt-work-wtf/#findComment-1439539 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 Link to comment https://forums.phpfreaks.com/topic/279893-the-easiest-code-in-the-world-and-yet-it-doesnt-work-wtf/#findComment-1439541 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.