Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-16T19:05:22.990Z
Answers.LastActivityDate: 2016-09-16T19:39:34.840Z
Answers.LastEditDate: 2016-09-16T19:39:34.840Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <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>
  
Tags: <datetime><filter><group><plugin-amforms>
Title: Group by day does strange exeptions
ThreadText: # 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 %}
    <ul>
      {% for entry in entriesInDay %}
        {% if loop.first %}<h2>{{ entry.datum | date('d.m.Y') }}</h2>{% endif %}
         <li>{{ entry.datum | date('d. M Y') }} | {{ entry.vorname }} {{ entry.nachname }}</li>
      {% endfor %}
    </ul>
  {% 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 `<h2>` tag inside your `<ul>`, 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 %}
      <div class="day">
          <h2>{{ day|date('d.m.Y') }}</h2>
          <ul>
              {% for entry in entries %}
                  {{ entry.datum | date('d. M Y') }} | {{ entry.vorname }} {{ entry.nachname }}
              {% endfor %}
          </ul>
      </div>
  {% 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](https://github.com/TopShelfCraft/SuperSort):
  
  ```
  {% set entriesByDay = allSubmissions | group(groupVerbund) | supersort('ksort') %}
  
  ```
  
  
  ---
  
  