Show when your business is open or closed

A nice addition to any business site is to display your opening hours. Use it anywhere you like, with your phone number, support form, or company address.

Basic code

In this example, I’m using a conditional with the {current_time} queried against the current hour using the %H date/time code variable for 24 hour clock time, so “17” is 5.00pm.

{if "{current_time format='%H'}" >= 09 AND "{current_time format='%H'}" < 17}
  We're open for business!
{if:else}
  We're closed right now
{/if}

What this does is display the open message if the time is greater than or equal to 9.00am and before 5.00pm (no later than 4.59pm to be precise), otherwise show the closed message.

But we don’t work weekends!

That’s no problem. We have the %N date/time code that gives us day numbers to play with, where “1” is for Monday through to “7” for Sunday.

What we can do now is wrap our basic code with another conditional to check for the current day.

{if "{current_time format='%N'}" < 6}
  {if "{current_time format='%H'}" >= 09 AND "{current_time format='%H'}" < 17}
    We're open for business!
  {if:else}
    We're closed right now
  {/if}
{if:else}
  We don't work weekends, come back on Monday.
{/if}

So what we’re saying here, if the current day is less than 6 (i.e. before Saturday/Sunday) then output our daily open/closed message, otherwise say “we’re closed for the weekend”.

Caveats

Rob Allen's avatar
Rob Allen

I've been creating web sites since 1998, and working with ExpressionEngine since 2007, building and maintaining sites for individuals, charities, organisations and businesses. I love using EE to do…

Comments 0

Be the first to comment!