Checkbox array for days of the week 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') &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 %}


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') &gt; theCenter.openTime|date('Hi') and 'now'|date('Hi', 'America/Denver') &lt; 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') &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 %}


Which outputs this:



I need it to only show the center is closed once.
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') &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 %}