djfox Posted February 14, 2008 Share Posted February 14, 2008 Ok, first, here is the code: <?php $checkhour = strftime("%H", time()); if ($checkhour == 00) { $dayname = "Evening"; $daynum = "2"; } elseif ($checkhour == 01) { $dayname = "Night"; $daynum = "3"; } elseif ($checkhour == 02) { $dayname = "Night"; $daynum = "3"; } elseif ($checkhour == 03) { $dayname = "Night"; $daynum = "3"; } elseif ($checkhour == 04) { $dayname = "Night"; $daynum = "3"; } elseif ($checkhour == 05) { $dayname = "Night"; $daynum = "3"; } elseif ($checkhour == 06) { $dayname = "Morning"; $daynum = "4"; } elseif ($checkhour == 07) { $dayname = "Day"; $daynum = "1"; } elseif ($checkhour == 08) { $dayname = "Day"; $daynum = "1"; } elseif ($checkhour == 09) { $dayname = "Day"; $daynum = "1"; } elseif ($checkhour == 10) { $dayname = "Day"; $daynum = "1"; } elseif ($checkhour == 11) { $dayname = "Day"; $daynum = "1"; } elseif ($checkhour == 12) { $dayname = "Evening"; $daynum = "2"; } elseif ($checkhour == 13) { $dayname = "Night"; $daynum = "3"; } elseif ($checkhour == 14) { $dayname = "Night"; $daynum = "3"; } elseif ($checkhour == 15) { $dayname = "Night"; $daynum = "3"; } elseif ($checkhour == 16) { $dayname = "Night"; $daynum = "3"; } elseif ($checkhour == 17) { $dayname = "Night"; $daynum = "3"; } elseif ($checkhour == 18) { $dayname = "Morning"; $daynum = "4"; } elseif ($checkhour == 19) { $dayname = "Day"; $daynum = "1"; } elseif ($checkhour == 20) { $dayname = "Day"; $daynum = "1"; } elseif ($checkhour == 21) { $dayname = "Day"; $daynum = "1"; } elseif ($checkhour == 22) { $dayname = "Day"; $daynum = "1"; } elseif ($checkhour == 23) { $dayname = "Day"; $daynum = "1"; } ?> Here is what the code should do: Figure out what hour the time is and declare if the time is day/night/morning/evening depending on what the hour is. What the problem is: It seems to have a problem with hour 08. All the other hour times work but that one. And by work I mean it will echo $dayname. With hour 08, it echos nothing. EDIT: Anyone know what happened to the "Topic Solved" tab? Past few posts of mine I cannot find that to mark my topics solved. Quote Link to comment https://forums.phpfreaks.com/topic/91072-can-anyone-figure-out-what-is-wrong/ Share on other sites More sharing options...
djfox Posted February 14, 2008 Author Share Posted February 14, 2008 I`ve tried this code: <?php if ($checkhour == 00 || $checkhour == 12) { $dayname = "Evening"; $daynum = "2"; } elseif ($checkhour == 01 || $checkhour == 02 || $checkhour == 03 || $checkhour == 04 || $checkhour == 05 || $checkhour == 13 || $checkhour == 14 || $checkhour == 15 || $checkhour == 16 || $checkhour == 17) { $dayname = "Night"; $daynum = "3"; } elseif ($checkhour == 06 || $checkhour == 18) { $dayname = "Morning"; $daynum = "4"; } elseif ($checkhour == 07 || $checkhour == 08 || $checkhour == 09 || $checkhour == 10 || $checkhour == 11 || $checkhour == 19 || $checkhour == 20 || $checkhour == 21 || $checkhour == 22 || $checkhour == 23) { $dayname = "Day"; $daynum = "1"; } ?> But it still will not work for hour 08. Quote Link to comment https://forums.phpfreaks.com/topic/91072-can-anyone-figure-out-what-is-wrong/#findComment-466794 Share on other sites More sharing options...
revraz Posted February 14, 2008 Share Posted February 14, 2008 The Topic Solved button got lost when they did the update. Have you tried echoing $checkhour to see what it displays when you pick 08? Quote Link to comment https://forums.phpfreaks.com/topic/91072-can-anyone-figure-out-what-is-wrong/#findComment-466801 Share on other sites More sharing options...
djfox Posted February 14, 2008 Author Share Posted February 14, 2008 The Topic Solved button got lost when they did the update. Oh dear. Have you tried echoing $checkhour to see what it displays when you pick 08? It displays nothing. Quote Link to comment https://forums.phpfreaks.com/topic/91072-can-anyone-figure-out-what-is-wrong/#findComment-466803 Share on other sites More sharing options...
laffin Posted February 14, 2008 Share Posted February 14, 2008 what's the purpose of the % in strtotime? this wud result as '%01' which when converted to integer will take the '%' and return a 0 Quote Link to comment https://forums.phpfreaks.com/topic/91072-can-anyone-figure-out-what-is-wrong/#findComment-466810 Share on other sites More sharing options...
revraz Posted February 14, 2008 Share Posted February 14, 2008 How about $checkhour = date("H"); Quote Link to comment https://forums.phpfreaks.com/topic/91072-can-anyone-figure-out-what-is-wrong/#findComment-466811 Share on other sites More sharing options...
revraz Posted February 14, 2008 Share Posted February 14, 2008 That's a strftime parameter. what's the purpose of the % in strtotime? this wud result as '%01' which when converted to integer will take the '%' and return a 0 Quote Link to comment https://forums.phpfreaks.com/topic/91072-can-anyone-figure-out-what-is-wrong/#findComment-466814 Share on other sites More sharing options...
djfox Posted February 14, 2008 Author Share Posted February 14, 2008 How about $checkhour = date("H"); That got it working. Thanks a bunch, buddy. ^^ Quote Link to comment https://forums.phpfreaks.com/topic/91072-can-anyone-figure-out-what-is-wrong/#findComment-466824 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.