mattpark Posted June 19, 2008 Share Posted June 19, 2008 Hi All, I'm dusting off my php skills, which have unfortunately become a little too dusty. I wonder if you may help me? The Goal: Display "Open" between 9am - 5pm, Monday - Friday. Display "Closed" outside of these hours. I currently have: $date = date('g:ia \\o\n l F dS, Y'); $status = ((time() >= mktime(9,0,0,date('m'),date('j'),date('Y'))) && (time() <= mktime(17,0,0,date('m'),date('j'),date('Y')))) ? '<span class="green">open</span>' : '<span class="red">closed</span>'; Which works well, however doesn't take in to account Sat and Sun. Commons on how to update this would be greatly appreciated! Cheers, Matt 0 Quote Link to comment Share on other sites More sharing options...
brianoz Posted June 24, 2008 Share Posted June 24, 2008 I couldn't understand that; here's what I thought was simpler ... (completely untested though!) $dow = date('D'); $hour = date('H'); $isclosed = $dow == "Sat" || $dow == "Sun" || $hour < 9 || $hour > 17; $status = $isclosed ? '<span class="green">open</span>' : '<span class="red">closed</span>'; 0 Quote Link to comment Share on other sites More sharing options...
arhost Posted June 24, 2008 Share Posted June 24, 2008 I couldn't understand that; here's what I thought was simpler ... (completely untested though!) $dow = date('D'); $hour = date('H'); $isclosed = $dow == "Sat" || $dow == "Sun" || $hour < 9 || $hour > 17; $status = $isclosed ? '<span class="green">open</span>' : '<span class="red">closed</span>'; It's displaying "open" instead of closed, time here is: 19:01. Edit: It's working perfectly Thanks. 0 Quote Link to comment Share on other sites More sharing options...
mattpark Posted June 24, 2008 Author Share Posted June 24, 2008 Hi Guys, Many thanks for your responses. To confirm, the following code works perfectly: $dow = date('D'); $hour = date('H'); $isclosed = $dow == "Sat" || $dow == "Sun" || $hour < 9 || $hour > 16; $status =$isclosed ?'<span class="red">closed</span></a>.' : '<span class="green">open</span>'; Again, thank your for your help. Matt 0 Quote Link to comment Share on other sites More sharing options...
brianoz Posted June 24, 2008 Share Posted June 24, 2008 It's displaying "open" instead of closed, time here is:19:01. Edit: It's working perfectly Thanks. Just for the record, Matt's version is correct, I had open and closed switched in the last line. 0 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.