<p>When you specifically group on <code>dateField.day</code> (in your case, the <code>|group('datum.day')</code> part), the group filter won't care about the month or year for the date field – only the day. This means that any entry posted on the 22nd of any month in any year will be grouped together, which is probably not what you want.</p>

<p>In this case, the solution is simply to group on the date field without a postfix (which will create an array index for each unique day/date):</p>

<pre><code>{% set groupVerbund = 'datum' %}
{% set entriesByDay = allSubmissions | group(groupVerbund) %}
</code></pre>

<p>Additionally, I can't help but notice the <code>&lt;h2&gt;</code> tag inside your <code>&lt;ul&gt;</code>, which is strictly speaking non-valid HTML. A better solution might be to do something like this (this would also save you a conditional):</p>

<pre><code>{% for day, entries in entriesByDay %}
    &lt;div class="day"&gt;
        &lt;h2&gt;{{ day|date('d.m.Y') }}&lt;/h2&gt;
        &lt;ul&gt;
            {% for entry in entries %}
                {{ entry.datum | date('d. M Y') }} | {{ entry.vorname }} {{ entry.nachname }}
            {% endfor %}
        &lt;/ul&gt;
    &lt;/div&gt;
{% endfor %}
</code></pre>

<p>One final issue is sorting – you'll probably see the dates mixed up, which is just how the <code>|group</code> filter works – it only groups, and cares less about sorting. Basically, the <code>group</code> filter will return an array that looks something like this:</p>

<pre><code>[
    '2016-10-22' =&gt; [array of entries],
    '2017-01-22' =&gt; [array of entries],
    '2016-11-13' =&gt; [array of entries],
]
</code></pre>

<p>...which means that if you want the output to be sorted by date, you'll need to sort that array on its <em>keys</em> (i.e. the dates) – something Twig's native <code>sort</code> filter regrettably doesn't do, but which is easily accomplished with the fantastic <a href="https://github.com/TopShelfCraft/SuperSort" rel="nofollow">SuperSort plugin</a>:</p>

<pre><code>{% set entriesByDay = allSubmissions | group(groupVerbund) | supersort('ksort') %}
</code></pre>

CC BY-SA 3.0
2016-09-16T19:05:22.990Z
2016-09-16T19:39:34.840Z
2016-09-16T19:39:34.840Z
Mats Mikkel Rummelhoff
<p>I have a list of forms which I want to sort by day:</p>

<pre><code>{% set groupVerbund = 'datum.day' %}

{% set allSubmissions = craft.amForms.submissions({
   formHandle: 'reservation',
   limit: null}).find()
%}
{% set entriesByDay = allSubmissions | group(groupVerbund) %}


{% for entriesInDay in entriesByDay %}
  &lt;ul&gt;
    {% for entry in entriesInDay %}
      {% if loop.first %}&lt;h2&gt;{{ entry.datum | date('d.m.Y') }}&lt;/h2&gt;{% endif %}
       &lt;li&gt;{{ entry.datum | date('d. M Y') }} | {{ entry.vorname }} {{ entry.nachname }}&lt;/li&gt;
    {% endfor %}
  &lt;/ul&gt;
{% endfor %}
</code></pre>

<p>This works but there are two entries which just are at the wrong place:</p>

<pre><code>Entries in: 22. Okt. 2016
------------------
22. Okt. 2016 | Name Surname
22. Okt. 2016 | Name Surname
22. Okt. 2016 | Name Surname
22. Okt. 2016 | Name Surname
22. Okt. 2016 | Name Surname
22. Okt. 2016 | Name Surname
22. Okt. 2016 | Name Surname
22. Okt. 2016 | Name Surname
22. Jan. 2017 | Name Surname // This one is wrong
22. Okt. 2016 | Name Surname
22. Okt. 2016 | Name Surname

Entries in: 13. Nov.2016
------------------
13. Nov. 2016 | Name Surname
13. Dez. 2016 | Name Surname // This one is wrong
13. Nov. 2016 | Name Surname
</code></pre>

<p>Everything else is at the right place except these two entries. <code>{{ entry.datum}}</code> is a custom date field so it's not possible to add a wrong date format.</p>

<p>How can this be?</p>

<datetime><filter><group><plugin-amforms>
Group by day does strange exeptions
# Group by day does strange exeptions

(Asked by: username_0 on 2016-09-16)

I have a list of forms which I want to sort by day:
{% set groupVerbund = 'datum.day' %}

{% set allSubmissions = craft.amForms.submissions({
   formHandle: 'reservation',
   limit: null}).find()
%}
{% set entriesByDay = allSubmissions | group(groupVerbund) %}


{% for entriesInDay in entriesByDay %}
  
    {% for entry in entriesInDay %}
      {% if loop.first %}{{ entry.datum | date('d.m.Y') }}{% endif %}
       {{ entry.datum | date('d. M Y') }} | {{ entry.vorname }} {{ entry.nachname }}
    {% endfor %}
  
{% endfor %}

This works but there are two entries which just are at the wrong place:
Entries in: 22. Okt. 2016
------------------
22. Okt. 2016 | Name Surname
22. Okt. 2016 | Name Surname
22. Okt. 2016 | Name Surname
22. Okt. 2016 | Name Surname
22. Okt. 2016 | Name Surname
22. Okt. 2016 | Name Surname
22. Okt. 2016 | Name Surname
22. Okt. 2016 | Name Surname
22. Jan. 2017 | Name Surname // This one is wrong
22. Okt. 2016 | Name Surname
22. Okt. 2016 | Name Surname

Entries in: 13. Nov.2016
------------------
13. Nov. 2016 | Name Surname
13. Dez. 2016 | Name Surname // This one is wrong
13. Nov. 2016 | Name Surname

Everything else is at the right place except these two entries. {{ entry.datum}} is a custom date field so it's not possible to add a wrong date format.
How can this be?

**Tags:** datetime, filter, group, plugin-amforms


---

## 1 answers

### Answer by username_1 on 2016-09-16. Score: 4 | Accepted answer

When you specifically group on dateField.day (in your case, the |group('datum.day') part), the group filter won't care about the month or year for the date field – only the day. This means that any entry posted on the 22nd of any month in any year will be grouped together, which is probably not what you want.
In this case, the solution is simply to group on the date field without a postfix (which will create an array index for each unique day/date):
{% set groupVerbund = 'datum' %}
{% set entriesByDay = allSubmissions | group(groupVerbund) %}

Additionally, I can't help but notice the  tag inside your , which is strictly speaking non-valid HTML. A better solution might be to do something like this (this would also save you a conditional):
{% for day, entries in entriesByDay %}
    
        {{ day|date('d.m.Y') }}
        
            {% for entry in entries %}
                {{ entry.datum | date('d. M Y') }} | {{ entry.vorname }} {{ entry.nachname }}
            {% endfor %}
        
    
{% endfor %}

One final issue is sorting – you'll probably see the dates mixed up, which is just how the |group filter works – it only groups, and cares less about sorting. Basically, the group filter will return an array that looks something like this:
[
    '2016-10-22' => [array of entries],
    '2017-01-22' => [array of entries],
    '2016-11-13' => [array of entries],
]

...which means that if you want the output to be sorted by date, you'll need to sort that array on its keys (i.e. the dates) – something Twig's native sort filter regrettably doesn't do, but which is easily accomplished with the fantastic SuperSort plugin:
{% set entriesByDay = allSubmissions | group(groupVerbund) | supersort('ksort') %}


---

