Answers.Body: <p>You were close!  In Craft 3, <code>postDate</code> is a full PHP <a href="https://secure.php.net/manual/en/class.datetime.php" rel="nofollow noreferrer">DateTime object</a>, so it'd need to be something like:</p>
  
  <pre><code>{% set allEntriesByYear = allEntries|group('postDate|date("Y")') %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-15T23:41:40.863Z
Answers.LastActivityDate: 2018-06-15T23:41:40.863Z
Answers.UserDisplayName: Brad Bell
Body: <p>I am attempting to replicate the example from <a href="https://docs.craftcms.com/v3/templating/filters.html#group" rel="nofollow noreferrer">https://docs.craftcms.com/v3/templating/filters.html#group</a></p>
  
  <p>However, I am unable to access the <code>{{ year }}</code> in the first for loop inside the h2 element. It just shows up as an empty string. Anyone have an idea whats going on?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>{% set allEntries = craft.entries.section('weeklyDigests').all() %}
  {% set allEntriesByYear = allEntries|group('postDate.year') %}
  
  {% for year, entriesInYear in allEntriesByYear %}
     &lt;h2&gt;{{ year }}&lt;/h2&gt;
  
     &lt;ul&gt;
  
     {% for entry in entriesInYear %}
      &lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
     {% endfor %}
  
     &lt;/ul&gt;
  {% endfor %}
  </code></pre>
  
Tags: <templating><craft3><filter>
Title: Craft 3 Docs Group Filter Not Working
ThreadText: # Craft 3 Docs Group Filter Not Working
  
  (Asked by: username_0 on 2018-06-12)
  
  I am attempting to replicate the example from <https://docs.craftcms.com/v3/templating/filters.html#group>
  
  However, I am unable to access the `{{ year }}` in the first for loop inside the h2 element. It just shows up as an empty string. Anyone have an idea whats going on?
  
  Here is my code:
  
  ```
  {% set allEntries = craft.entries.section('weeklyDigests').all() %}
  {% set allEntriesByYear = allEntries|group('postDate.year') %}
  
  {% for year, entriesInYear in allEntriesByYear %}
     <h2>{{ year }}</h2>
  
     <ul>
  
     {% for entry in entriesInYear %}
      <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
     {% endfor %}
  
     </ul>
  {% endfor %}
  
  ```
  
  **Tags:** templating, craft3, filter
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-06-15. Score: 1 | Accepted answer
  
  You were close! In Craft 3, `postDate` is a full PHP [DateTime object](https://secure.php.net/manual/en/class.datetime.php), so it'd need to be something like:
  
  ```
  {% set allEntriesByYear = allEntries|group('postDate|date("Y")') %}
  
  ```
  
  
  ---
  
  