<p>This should do what you're looking for:</p>

<pre><code>{% set closed = true %}

{% for dayOfWeek in theCenter.openWeekDay %}

    {% if 'now'|date('N') == dayOfWeek and 'now'|date('Hi', 'America/Denver') &gt; theCenter.openTime|date('Hi') and 'now'|date('Hi', 'America/Denver') &lt; theCenter.closeTime|date('Hi') %}
        {% set closed = false %}
    {% endif %}

{% endfor %}

{% if closed %}
    &lt;h3&gt;The center is CLOSED&lt;/h3&gt;
{% else %}
    &lt;h3&gt;The center is OPEN&lt;/h3&gt;
{% endif %}
</code></pre>

CC BY-SA 3.0
2016-01-04T02:03:42.487Z
2016-01-04T02:03:42.487Z
Brad Bell
<p>I'm attempting to create something within my template using global values and checkboxes. What I need this to do is "if it's one of the days of the week marked as open, as selected by a checkbox, and the time is between X and Y, then display that we are open, otherwise, say we are closed".</p>

<p>I have Monday through Sunday listed as checkboxes, and their values are set with Monday as 1, Tuesday as 2, etc, and I'm trying to compare it to 'now'|date('N'), which lists the day of the week as a number.</p>

<pre><code>{% for dayOfWeek in theCenter.openWeekDay %}

    {% if 'now'|date('N') == dayOfWeek and 'now'|date('Hi', 'America/Denver') &gt; theCenter.openTime|date('Hi') and 'now'|date('Hi', 'America/Denver') &lt; theCenter.closeTime|date('Hi') %}
        &lt;h3&gt;We are OPEN&lt;/h3&gt;
    {% else %}
        &lt;h3&gt;We are CLOSED&lt;/h3&gt;
    {% endif %}

{% endfor %}
</code></pre>

<p>I've selected Tuesday through Sunday as open by selecting their checkboxes in the globals form. The code above returns 5 'We are Closed' and 1 'We are Open' results. I just need it to check if today is one of the open days, and if it's between open and closing time, and display one result.</p>

<p>I've tried this:</p>

<pre><code>{% if 'now'|date('N') in dayOfWeek and 'now'|date('Hi', 'America/Denver') &gt; theCenter.openTime|date('Hi') and 'now'|date('Hi', 'America/Denver') &lt; theCenter.closeTime|date('Hi') %}
</code></pre>

<p>but it returns 6 'We are Closed'. I've been trying to figure this out for several hours, but the documentation doesn't seem to be made for what I want to do, and I'm probably looking in the wrong place.</p>

<p>Any suggestions on how I could get this to work?</p>

<p><strong>EDIT</strong></p>

<p>Here's the entire script:</p>

<pre><code>{% if 'now'|date('z', 'America/Denver') &gt; theCenter.startWinterSeason|date('z') or 'now'|date('z', 'America/Denver') &lt; theCenter.endWinterSeason|date('z') %}
    {% for dayOfWeek in theCenter.openDaysWinter %}
        {% if dayOfWeek.selected and 'now'|date('N') == dayOfWeek and 'now'|date('Hi', 'America/Denver') &gt; theCenter.openTimeWinter|date('Hi') and 'now'|date('Hi', 'America/Denver') &lt; theCenter.closeTimeWinter|date('Hi') %}
            &lt;h3&gt;The center is OPEN&lt;/h3&gt;
        {% else %}
            &lt;h3&gt;The center is CLOSED&lt;/h3&gt;
        {% endif %}
    {% endfor %}
    &lt;div class="infoPane"&gt;
        &lt;p&gt;&lt;i class="uk-icon-clock-o"&gt;&lt;/i&gt;&amp;nbsp;{{ theCenter.hoursTitleWinter }}&lt;/p&gt;
        &lt;p&gt;Tuesday &amp;mdash; Saturday&lt;br&gt;{{ theCenter.openTimeWinter|date('g:i A') }} to {{ theCenter.closeTimeWinter|date('g:i A') }}&lt;/p&gt;
        &lt;p class="uk-text-small"&gt;{{ theCenter.timeNotes|raw }}&lt;/p&gt;
    &lt;/div&gt;

{% elseif 'now'|date('z', 'America/Denver') &gt; theCenter.startSummerSeason|date('z') and 'now'|date('z', 'America/Denver') &lt; theCenter.endSummerSeason|date('z') %}
    {% for dayOfWeek in theCenter.openDaysSummer %}
        {% if dayOfWeek.selected and 'now'|date('N') == dayOfWeek and 'now'|date('Hi', 'America/Denver') &gt; theCenter.openTimeSummer|date('Hi') and 'now'|date('Hi', 'America/Denver') &lt; theCenter.closeTimeSummer|date('Hi') %}
            &lt;h3&gt;The center is OPEN&lt;/h3&gt;
        {% else %}
            &lt;h3&gt;The center is CLOSED&lt;/h3&gt;
        {% endif %}
    {% endfor %}
    &lt;div class="infoPane"&gt;
        &lt;p&gt;&lt;i class="uk-icon-clock-o"&gt;&lt;/i&gt;&amp;nbsp;{{ theCenter.hoursTitleSummer }}&lt;/p&gt;
        &lt;p&gt;Tuesday &amp;mdash; Saturday&lt;br&gt;{{ theCenter.openTimeSummer|date('g:i A') }} to {{ theCenter.closeTimeSummer|date('g:i A') }}&lt;/p&gt;
        &lt;p class="uk-text-small"&gt;{{ theCenter.timeNotes|raw }}&lt;/p&gt;
    &lt;/div&gt;
{% else %}
    &lt;h3&gt;EPIC FAIL&lt;/h3&gt;
{% endif %}
</code></pre>

<p>Which outputs this:</p>

<p><a href="https://i.sstatic.net/WmcCe.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/WmcCe.jpg" alt="Output"></a></p>

<p>I need it to only show the center is closed once.</p>

CC BY-SA 3.0
2016-01-03T21:27:04.310Z
I just setup a test case using virtually identical code and it worked as expected for me.  Is your Craft install set to `America/Denver` under Settings->General?  Also, have you seen https://github.com/pixelandtonic/StoreHours?
Brad Bell
CC BY-SA 3.0
2016-01-03T21:42:02.947Z
I'll test out Store Hours and see if that works. Is there more documentation available on it?

Also, the timezone is indeed, set to Denver.
Dustin C
CC BY-SA 3.0
2016-01-03T21:44:29.947Z
I'm looking at this, and I realise that the reason it's spitting out "We are Closed" so many times is because it's stuck a loop. The hours are simple enough that we just want the hours listed on the site as "The center is open. Hours: Tuesday-Sunday, 9:00 AM to 4:30 PM" -- we don't want to list the hours out for each day of the week individually.
Dustin C
CC BY-SA 3.0
2016-01-03T21:52:06.463Z
Hey @BradBell -- thanks for the Store Hours suggestion, but it's not giving me the level of control that I would need. I'll need to stick with this one for now.
Dustin C
CC BY-SA 3.0
2016-01-03T22:46:40.583Z
I'm not following... the hours aren't being output at all, it's just looping on the days.  Is your `openTime` and `closeTime` date/time fields set to just display the times?
Brad Bell
CC BY-SA 3.0
2016-01-04T01:29:18.287Z
The hours are output farther on. I didn't include that part of the script for brevity sake, as this is what I was having issues with. :)
Dustin C
CC BY-SA 3.0
2016-01-04T01:56:22.063Z
@BradBell - Added the full script on the original post.
Dustin C
CC BY-SA 3.0
2016-01-04T01:58:22.370Z
Regardless, I was able to get it to work with your original code.  So I'd probably focus on that.
Brad Bell
CC BY-SA 3.0
2016-01-04T02:00:35.027Z
Oh, maybe I misunderstood.  If it's closed you only want it to show once?
Brad Bell
<checkboxes>
Checkbox array for days of the week
# Checkbox array for days of the week

(Asked by: username_0 on 2016-01-03)

I'm attempting to create something within my template using global values and checkboxes. What I need this to do is "if it's one of the days of the week marked as open, as selected by a checkbox, and the time is between X and Y, then display that we are open, otherwise, say we are closed".
I have Monday through Sunday listed as checkboxes, and their values are set with Monday as 1, Tuesday as 2, etc, and I'm trying to compare it to 'now'|date('N'), which lists the day of the week as a number.
{% for dayOfWeek in theCenter.openWeekDay %}

    {% if 'now'|date('N') == dayOfWeek and 'now'|date('Hi', 'America/Denver') > theCenter.openTime|date('Hi') and 'now'|date('Hi', 'America/Denver') < theCenter.closeTime|date('Hi') %}
        We are OPEN
    {% else %}
        We are CLOSED
    {% endif %}

{% endfor %}

I've selected Tuesday through Sunday as open by selecting their checkboxes in the globals form. The code above returns 5 'We are Closed' and 1 'We are Open' results. I just need it to check if today is one of the open days, and if it's between open and closing time, and display one result.
I've tried this:
{% if 'now'|date('N') in dayOfWeek and 'now'|date('Hi', 'America/Denver') > theCenter.openTime|date('Hi') and 'now'|date('Hi', 'America/Denver') < theCenter.closeTime|date('Hi') %}

but it returns 6 'We are Closed'. I've been trying to figure this out for several hours, but the documentation doesn't seem to be made for what I want to do, and I'm probably looking in the wrong place.
Any suggestions on how I could get this to work?
EDIT
Here's the entire script:
{% if 'now'|date('z', 'America/Denver') > theCenter.startWinterSeason|date('z') or 'now'|date('z', 'America/Denver') < theCenter.endWinterSeason|date('z') %}
    {% for dayOfWeek in theCenter.openDaysWinter %}
        {% if dayOfWeek.selected and 'now'|date('N') == dayOfWeek and 'now'|date('Hi', 'America/Denver') > theCenter.openTimeWinter|date('Hi') and 'now'|date('Hi', 'America/Denver') < theCenter.closeTimeWinter|date('Hi') %}
            The center is OPEN
        {% else %}
            The center is CLOSED
        {% endif %}
    {% endfor %}
    
         {{ theCenter.hoursTitleWinter }}
        Tuesday — Saturday{{ theCenter.openTimeWinter|date('g:i A') }} to {{ theCenter.closeTimeWinter|date('g:i A') }}
        {{ theCenter.timeNotes|raw }}
    

{% elseif 'now'|date('z', 'America/Denver') > theCenter.startSummerSeason|date('z') and 'now'|date('z', 'America/Denver') < theCenter.endSummerSeason|date('z') %}
    {% for dayOfWeek in theCenter.openDaysSummer %}
        {% if dayOfWeek.selected and 'now'|date('N') == dayOfWeek and 'now'|date('Hi', 'America/Denver') > theCenter.openTimeSummer|date('Hi') and 'now'|date('Hi', 'America/Denver') < theCenter.closeTimeSummer|date('Hi') %}
            The center is OPEN
        {% else %}
            The center is CLOSED
        {% endif %}
    {% endfor %}
    
         {{ theCenter.hoursTitleSummer }}
        Tuesday — Saturday{{ theCenter.openTimeSummer|date('g:i A') }} to {{ theCenter.closeTimeSummer|date('g:i A') }}
        {{ theCenter.timeNotes|raw }}
    
{% else %}
    EPIC FAIL
{% endif %}

Which outputs this:

I need it to only show the center is closed once.

**Tags:** checkboxes
> **Comments:**
> **username_1**: I just setup a test case using virtually identical code and it worked as expected for me.  Is your Craft install set to `America/Denver` under Settings->General?  Also, have you seen https://github.com/pixelandtonic/StoreHours?  
> **username_0**: I'll test out Store Hours and see if that works. Is there more documentation available on it?  Also, the timezone is indeed, set to Denver.  
> **username_0**: I'm looking at this, and I realise that the reason it's spitting out "We are Closed" so many times is because it's stuck a loop. The hours are simple enough that we just want the hours listed on the site as "The center is open. Hours: Tuesday-Sunday, 9:00 AM to 4:30 PM" -- we don't want to list the hours out for each day of the week individually.  
> **username_0**: Hey @BradBell -- thanks for the Store Hours suggestion, but it's not giving me the level of control that I would need. I'll need to stick with this one for now.  
> **username_1**: I'm not following... the hours aren't being output at all, it's just looping on the days.  Is your `openTime` and `closeTime` date/time fields set to just display the times?  
> **username_0**: The hours are output farther on. I didn't include that part of the script for brevity sake, as this is what I was having issues with. :)  
> **username_0**: @BradBell - Added the full script on the original post.  
> **username_1**: Regardless, I was able to get it to work with your original code.  So I'd probably focus on that.  
> **username_1**: Oh, maybe I misunderstood.  If it's closed you only want it to show once?  

---

## 1 answers

### Answer by username_1 on 2016-01-04. Score: 2 | Accepted answer

This should do what you're looking for:
{% set closed = true %}

{% for dayOfWeek in theCenter.openWeekDay %}

    {% if 'now'|date('N') == dayOfWeek and 'now'|date('Hi', 'America/Denver') > theCenter.openTime|date('Hi') and 'now'|date('Hi', 'America/Denver') < theCenter.closeTime|date('Hi') %}
        {% set closed = false %}
    {% endif %}

{% endfor %}

{% if closed %}
    The center is CLOSED
{% else %}
    The center is OPEN
{% endif %}


---

