Answers.Body: <p>I think that the official Craft CMS documentation provides an answer to your question really clearly: <a href="https://craftcms.com/support/entry-archive" rel="nofollow noreferrer">https://craftcms.com/support/entry-archive</a></p>
  
  <p>For example,</p>
  
  <pre><code>{% set childEntires = craft.entries({
      'section': 'mySection',
      'level': 2,
      'descendantOf': author.id
  })%}
  
  {% for date, entries in childEntires | group("myDate|date('Y')") %}
      &lt;h2&gt;{{ date }}&lt;/h2&gt;
      &lt;ul&gt;
          {% for entry in entries %}
              &lt;li&gt;{{ entry.myDate | Y }} &gt; {{ entry.type.name }} - {{ entry.foo }}&lt;/li&gt;
          {% endfor %}
      &lt;/ul&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-10T18:38:18.877Z
Answers.Text: Would you mind expanding this answer to include some of the information found at that URL? Link-only answers are frowned upon, as they may change or break in the future.
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-10T18:06:16.150Z
Answers.LastActivityDate: 2017-03-10T19:01:24.007Z
Answers.LastEditDate: 2017-03-10T19:01:24.007Z
Answers.UserDisplayName: ianp
Answers.Body: <p>You're currently grouping on the <code>myDate</code> field, which essentially creates a new array index for each date (e.g. <code>2016-01-01</code>) which is why you're getting your current output.</p>
  
  <p>To group by <em>year</em>, this should do the trick:</p>
  
  <pre><code>{% for year, entries in entries|group('myDate.year') %}
      &lt;h4&gt;{{ year }}&lt;/h4&gt;
      &lt;ul&gt;
          {% for entry in entries %}
              ...
          {% endfor %}
      &lt;/ul&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-10T13:23:44.770Z
Answers.Text: Ah - yes! I was thinking about the `myDate` field as a whole, not get just *the* year from it. Thank you!
Answers.UserDisplayName: Damon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-10T09:57:33.293Z
Answers.LastActivityDate: 2016-09-10T09:57:33.293Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I am getting all entries from a section like this:</p>
  
  <pre><code>// get the parent entry.
  {% set author = craft.entries.section('mySection').authorId(currentUser.id).first() %}
  
  // get the child entries from the parent.
  {% set entires = craft.entries({
      'section': 'mySection',
      'level': 2,
      'descendantOf': author.id
   })%}
  
  // myDate is a dateTime filed (yyyy-mm-dd)
  
  {% for year, entry in entries|group('myDate') %}
              &lt;h4&gt;{{ year|date('Y') }}&lt;/h4&gt;
              &lt;ul&gt;
                  {% for entry in entries %}
                      {% if attempt.myDate|date('Y') == year|date('Y') %}
                          &lt;li&gt;{{ entry.myDate }} &gt; {{ entry.type.name }} - {{ entry.foo }}&lt;/li&gt;
                      {% endif %}
                  {% endfor %}
              &lt;/ul&gt;
          {% endfor %}
  </code></pre>
  
  <p>What I have is close, however, it's outputting multiple years. For example, </p>
  
  <pre><code>2016
    [entry]
  
  2016
    [entry]
  
  2015
    [entry]
  
   ...
  </code></pre>
  
  <p>I'm trying to group all of the child entries by year. For example, if I have 3 entires with the same year (2016) I am trying to show: </p>
  
  <pre><code>2016
    [entry]
    [entry]
    [entry]
  
  2015
    [entry]
  
  2014
    [entry]
    [entry]
  
  ...
  </code></pre>
  
  <p>Thank you for any suggestions!</p>
  
Tags: <datetime><group>
Title: How can I group entries based on a dateTime field?
ThreadText: # How can I group entries based on a dateTime field?
  
  (Asked by: username_0 on 2016-09-10)
  
  I am getting all entries from a section like this:
  
  ```
  // get the parent entry.
  {% set author = craft.entries.section('mySection').authorId(currentUser.id).first() %}
  
  // get the child entries from the parent.
  {% set entires = craft.entries({
      'section': 'mySection',
      'level': 2,
      'descendantOf': author.id
   })%}
  
  // myDate is a dateTime filed (yyyy-mm-dd)
  
  {% for year, entry in entries|group('myDate') %}
              <h4>{{ year|date('Y') }}</h4>
              <ul>
                  {% for entry in entries %}
                      {% if attempt.myDate|date('Y') == year|date('Y') %}
                          <li>{{ entry.myDate }} > {{ entry.type.name }} - {{ entry.foo }}</li>
                      {% endif %}
                  {% endfor %}
              </ul>
          {% endfor %}
  
  ```
  
  What I have is close, however, it's outputting multiple years. For example,
  
  ```
  2016
    [entry]
  
  2016
    [entry]
  
  2015
    [entry]
  
   ...
  
  ```
  
  I'm trying to group all of the child entries by year. For example, if I have 3 entires with the same year (2016) I am trying to show:
  
  ```
  2016
    [entry]
    [entry]
    [entry]
  
  2015
    [entry]
  
  2014
    [entry]
    [entry]
  
  ...
  
  ```
  
  Thank you for any suggestions!
  
  **Tags:** datetime, group
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2016-09-10. Score: 6 | Accepted answer
  
  You're currently grouping on the `myDate` field, which essentially creates a new array index for each date (e.g. `2016-01-01`) which is why you're getting your current output.
  
  To group by *year*, this should do the trick:
  
  ```
  {% for year, entries in entries|group('myDate.year') %}
      <h4>{{ year }}</h4>
      <ul>
          {% for entry in entries %}
              ...
          {% endfor %}
      </ul>
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: Ah - yes! I was thinking about the `myDate` field as a whole, not get just *the* year from it. Thank you!  
  
  ---
  
  ### Answer by username_1 on 2017-03-10. Score: 1
  
  I think that the official Craft CMS documentation provides an answer to your question really clearly: <https://craftcms.com/support/entry-archive>
  
  For example,
  
  ```
  {% set childEntires = craft.entries({
      'section': 'mySection',
      'level': 2,
      'descendantOf': author.id
  })%}
  
  {% for date, entries in childEntires | group("myDate|date('Y')") %}
      <h2>{{ date }}</h2>
      <ul>
          {% for entry in entries %}
              <li>{{ entry.myDate | Y }} > {{ entry.type.name }} - {{ entry.foo }}</li>
          {% endfor %}
      </ul>
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_2**: Would you mind expanding this answer to include some of the information found at that URL? Link-only answers are frowned upon, as they may change or break in the future.  
  
  ---
  
  