<p>Your <code>postDate.day</code> will output the number of the day in the month so if your entries <code>postdate</code> is 02.dd.yyyy your output is <code>2</code>. Your array index will be something like <code>[2, 3, 5, 12, 31]</code> thus these values will be converted from the timestamp into a readable day with<code>&lt;h2&gt;{{ day | date('Y-m-d') }}&lt;/h2&gt;</code>. The first timestamp (0) is <code>01.01.1970</code> because of your timezone you'll see only values around this date since you convert all the day numbers from 1-31 as timestamps to your given format. </p>

<p>In case you did not know: the <code>day</code> variable represents only the keys of the array and with <code>| group('postDate.day')</code> you define the keys. I think your goal is to have keys like <code>[ 'Monday', 'Tuesday'.... 'Sunday']</code>. Your filter will look like:</p>

<pre><code>{% for day, entriesInDay in agendaEntries | group('postDate|date('l')') %}
</code></pre>

CC BY-SA 3.0
2018-01-04T07:18:16.550Z
2018-01-04T07:24:40.570Z
2018-01-04T07:24:40.570Z
Robin Schambach
<p>I'm using the technique for creating an archive that's in the Craft docs: <a href="https://craftcms.com/support/entry-archive" rel="nofollow noreferrer">https://craftcms.com/support/entry-archive</a></p>

<p>I'm archiving by day, so my code looks like this:</p>

<pre><code>{% set agendaEntries = craft.entries.section('agenda').status('live,pending,expired').limit(null) %}

{% for day, entriesInDay in agendaEntries | group('postDate.day') %}
  &lt;h2&gt;{{ day | date('Y-m-d') }}&lt;/h2&gt;

  &lt;ul&gt;
    {% for entry in entriesInDay %}
       &lt;li&gt;
          {# entry data #}
       &lt;/li&gt;
    {% endfor %}
  &lt;/ul&gt;
{% endfor %}
</code></pre>

<p>The looping and grouping (heh) works great, but the <code>{{ day }}</code> variable doesn't correctly output the date, instead I get the day-before-Epoch date (1969-12-31).</p>

<p>I don't really understand how the <code>for</code> loop even knows what the <code>day</code> variable is, so I don't know how to troubleshoot.</p>

<forloop><group><archives>
Archive Not Returning Correct Date Variable
# Archive Not Returning Correct Date Variable

(Asked by: username_0 on 2018-01-04)

I'm using the technique for creating an archive that's in the Craft docs: https://craftcms.com/support/entry-archive
I'm archiving by day, so my code looks like this:
{% set agendaEntries = craft.entries.section('agenda').status('live,pending,expired').limit(null) %}

{% for day, entriesInDay in agendaEntries | group('postDate.day') %}
  {{ day | date('Y-m-d') }}

  
    {% for entry in entriesInDay %}
       
          {# entry data #}
       
    {% endfor %}
  
{% endfor %}

The looping and grouping (heh) works great, but the {{ day }} variable doesn't correctly output the date, instead I get the day-before-Epoch date (1969-12-31).
I don't really understand how the for loop even knows what the day variable is, so I don't know how to troubleshoot.

**Tags:** forloop, group, archives


---

## 1 answers

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

Your postDate.day will output the number of the day in the month so if your entries postdate is 02.dd.yyyy your output is 2. Your array index will be something like [2, 3, 5, 12, 31] thus these values will be converted from the timestamp into a readable day with{{ day | date('Y-m-d') }}. The first timestamp (0) is 01.01.1970 because of your timezone you'll see only values around this date since you convert all the day numbers from 1-31 as timestamps to your given format. 
In case you did not know: the day variable represents only the keys of the array and with | group('postDate.day') you define the keys. I think your goal is to have keys like [ 'Monday', 'Tuesday'.... 'Sunday']. Your filter will look like:
{% for day, entriesInDay in agendaEntries | group('postDate|date('l')') %}


---

