eldan88 Posted May 17, 2014 Share Posted May 17, 2014 Hey Guys. I am writing a function that will output to the user if a store is open or not. I wrote a fucntions named is_store_open() with a variable called $day which will have the current day of the week assigned to it. Lets say it is Saturday. it finds the case for "Saturday" and checks the opening time and closing time for Saturday. The problem that I am facing, is when the store is open past midnight on Saturday. It then won't check the case for saturday. Instead will check the case for Sunday. Which is not what I want, becuase it will show the store as closed when its open still open on "Saturday" I wrote a function below that checks to see if the previous day closing hours are greater then the current time. If its true then return true and I guess that should fix the problem. But when I wrote that it would give me an error saying that $saturday_close is undefined. I'm guessing its becuase its in a switch satement, and it does not equal to that day. I'm a little bit confused on how to set this up. If anyone has a suggestion I would really apprecaite your help. Thanks! function is_store_open(){ $set_time = strtotime("tomorrow"); // Lets just sat its Sunday for testing purposes $day = date("l", $set_time); $time_now = mktime("00", "00", "00"); // Now lets say the time now is 12:00am switch ($day) { case "Saturday": $open = "11:00"; $saturday_close = "1:00"; break; case "Sunday"; if($saturday_close > $time_now ){//If the $monday_close hours are greater then the current time return false the store is still open return true; } else { $open = "2:00"; $close = "22:00"; } break; } }// End of function if(is_store_open()) { echo "Oh no! There is still a glitch in the system the store needs to remain open"; } else { echo "The store is still open on Saturday"; } Quote Link to comment Share on other sites More sharing options...
Solution eldan88 Posted May 18, 2014 Author Solution Share Posted May 18, 2014 Nevermind guys I solved the issue! 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.