Jump to content

Rusty PHP


Recommended Posts

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

Link to comment
Share on other sites

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>';

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated