pyrodude Posted September 1, 2007 Share Posted September 1, 2007 A client of mine requested something for their page that lists their current business hours and whether the store is currently open or not. I thought I had this worked out fine until I was up late working on another aspect of the page and noticed it listing the store as open when it should not be. The code is as follows: <?php $currTime = date("g:i a"); $currDate = date("F jS, Y"); $currHour = date("H"); $currDay = date("l"); $currDayNum = date("d"); $currMonthNum = date("m"); $currStoreState = "<span style=\"color:red\"><strong>CLOSED</strong></span>"; $holCurrDay = "$currMonthNum $currDayNum"; // Holidays are: christmas day, new years day, thanksgiving day, labor day, memorial day, 4th of july, etc -- Still need to set up the math for memorial day, thanksgiving and labor day $holidays = Array( "Christmas" => "12 25", "NewYear" => "01 01", "July4th" => "07 04" ); foreach ($holidays as $value) { if ($holCurrDay == $value) { $isHoliday = true; } } if ($isHoliday == false) { if ($currDay != "Sunday") { // Closed Sundays, so exclude that if ($currDay == "Saturday") { if (($currHour > 08) && ($currHour < 17)) { // Saturday hours are 9am-5pm $currStoreState = "<span style=\"color:green\"><strong>OPEN</strong></span>"; } } elseif (($currHour > 07) && ($currHour <19)) { // All other days the store is open 8am-7pm $currStoreState = "<span style=\"color:green\"><strong>OPEN</strong></span>"; } } } echo "Today is $currDay, $currDate at $currTime<br /><br />We are currently: $currStoreState"; ?> The check lists the store as being open starting at 1:00am on Saturdays (however it closes at 5:00 like it should...) What I don't understand is that the code directly below it works just fine, and it's set up exactly the same. If someone can see my logic error somewhere in there, please let me know! Thanks Billy Quote Link to comment https://forums.phpfreaks.com/topic/67550-solved-weird-issue-with-if-statements/ Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 H: is 24 hours h: 12 hours notice the difference. Quote Link to comment https://forums.phpfreaks.com/topic/67550-solved-weird-issue-with-if-statements/#findComment-339283 Share on other sites More sharing options...
pyrodude Posted September 1, 2007 Author Share Posted September 1, 2007 Right. I'm using H because I want to compare it in a 24-hour timeline (Figured that would be easier for determining the difference between, say, 5am and 5pm) Are you suggesting I use h instead? Quote Link to comment https://forums.phpfreaks.com/topic/67550-solved-weird-issue-with-if-statements/#findComment-339287 Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 try if $currhour >8||<9 Quote Link to comment https://forums.phpfreaks.com/topic/67550-solved-weird-issue-with-if-statements/#findComment-339289 Share on other sites More sharing options...
pyrodude Posted September 1, 2007 Author Share Posted September 1, 2007 You realize that that would always be true, don't you? Just making sure. Anyway, I removed the preceding 0 from "08" and it seems to run fine again. Still not sure why it will work that way during the week just not on Saturdays. Ahh well, who am I to judge? Quote Link to comment https://forums.phpfreaks.com/topic/67550-solved-weird-issue-with-if-statements/#findComment-339294 Share on other sites More sharing options...
hostfreak Posted September 1, 2007 Share Posted September 1, 2007 You need to use quotes around your strings: <?php $currTime = date("g:i a"); $currDate = date("F jS, Y"); $currHour = date("H"); $currDay = date("l"); $currDayNum = date("d"); $currMonthNum = date("m"); $currStoreState = "<span style=\"color:red\"><strong>CLOSED</strong></span>"; $holCurrDay = "$currMonthNum $currDayNum"; // Holidays are: christmas day, new years day, thanksgiving day, labor day, memorial day, 4th of july, etc -- Still need to set up the math for memorial day, thanksgiving and labor day $holidays = Array( "Christmas" => "12 25", "NewYear" => "01 01", "July4th" => "07 04", ); foreach ($holidays as $value) { if ($holCurrDay == $value) { $isHoliday = true; } } if ($isHoliday == false) { if ($currDay != "Sunday") { // Closed Sundays, so exclude that if ($currDay == "Saturday") { if (($currHour > '08') && ($currHour < '17')) { // Saturday hours are 9am-5pm $currStoreState = "<span style=\"color:green\"><strong>OPEN</strong></span>"; } } elseif (($currHour > '07') && ($currHour < '19')) { // All other days the store is open 8am-7pm $currStoreState = "<span style=\"color:green\"><strong>OPEN</strong></span>"; } } } echo "Today is $currDay, $currDate at $currTime<br /><br />We are currently: $currStoreState"; ?> Sorry for the reformat on coding style, just a habit. Quote Link to comment https://forums.phpfreaks.com/topic/67550-solved-weird-issue-with-if-statements/#findComment-339300 Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 ah thanx for that i forgot about that Quote Link to comment https://forums.phpfreaks.com/topic/67550-solved-weird-issue-with-if-statements/#findComment-339301 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.