Answers.Body: <p>The <code>year</code> and  <code>month</code> variables are not defined, so you'd first have to get these from the 'date' variable.</p>
  
  <p>You could do this by using Twig's <code>split</code> function and splitting <code>date</code> by the space in between:</p>
  
  <pre><code>{% set dateParts = date | split(' ') %}
  {% set month = dateParts[1] %}
  {% set year = dateParts[0] %}
  
  &lt;a href="{{ year }}/{{ month }}"&gt;{{ date }}&lt;/a&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-09T18:05:04.503Z
Answers.LastActivityDate: 2015-01-09T18:05:04.503Z
Answers.UserDisplayName: Paul
Answers.Body: <p>I was going to suggest using twig's <code>date</code> filter to format the date as needed, but as Paul astutely pointed out in his comment, you don't really have a dateTime variable to work with. </p>
  
  <p>So my answer is use Paul's answer. ;)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-09T18:06:16.510Z
Answers.Text: Douglas, am I wrong or is `date` a string, not a DateTime object?
Answers.UserDisplayName: Paul
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-09T18:16:39.517Z
Answers.Text: It is. I noticed it as soon as I posted and fixed it. Thanks
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-09T18:19:11.903Z
Answers.Text: Douglas, this wouldn't work. Your `entry` variable now contains all entries, so you wouldn't be able to get a `postDate` from it ;)
Answers.UserDisplayName: Paul
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-09T18:33:55.683Z
Answers.Text: You're right Paul! Remind me never to answer questions before my first cup of coffee please.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-09T18:34:34.560Z
Answers.Text: Coffee? Just finishing my first glass of whisky ;)
Answers.UserDisplayName: Paul
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-09T18:05:17.417Z
Answers.LastActivityDate: 2015-01-09T18:30:05.977Z
Answers.LastEditDate: 2015-01-09T18:30:05.977Z
Answers.UserDisplayName: Douglas McDonald
Answers.Body: <p>If I understand your example correctly, a simple hyphen would do the trick &mdash; "YYYY-MM" is a format the <code>date</code> filter recognizes.</p>
  
  <pre><code>{% set entries = ... %}
  {% set entriesByMonth = entries|group('postDate|date("Y-m")') %}
  {% for month, entries in entriesByMonth %}
    &lt;li&gt;
        &lt;a href="{{ month|date("Y") }}/{{ month|date("m") }}"&gt;
          {{ entries | length }} entries in {{ month|date("F Y") }}
        &lt;/a&gt;
    &lt;/li&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-12T14:50:37.007Z
Answers.Text: I actually like Micahel's answer the best as there is no extra variables needed.
Answers.UserDisplayName: Siebird
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-10T00:56:42.673Z
Answers.LastActivityDate: 2015-01-10T00:56:42.673Z
Answers.UserDisplayName: Michael Rog
Body: <p>Having issues trying to access the year &amp; month variable when grouping entries by month-year. The code is outputting the desired results (ie. December 2014), however I would like to format the url by 'year/month'.</p>
  
  <h3>Archives</h3>
  
  <p>
      <p>Browse news &amp; articles for the last year.</p></p>
  
  <pre><code>{% set allEntries = craft.entries.section('news').limit(null) %}
  &lt;ul&gt;
  {% for date, entries in allEntries | group('postDate|date("F Y")') %}
      &lt;li&gt;&lt;a href="{{ year }}/{{ month }}"&gt;{{ date }}&lt;/a&gt;&lt;/li&gt;
  {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p> </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-09T18:16:02.077Z
Comments.Text: Both answers give me the desired results. Now I'm wondering what is the better answer? Paul's splits the `date` variable and Douglas use the DateTime object
Comments.UserDisplayName: Siebird
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-10T00:59:38.200Z
Comments.Text: Douglass is on the right track. You can *get* a DateTime to [re]format if you your year-month variable is in a format the `date` filter recognizes. I added a code snippet that I hope illustrates this helpfully.
Comments.UserDisplayName: Michael Rog
Tags: <entries><group>
Title: Need to access year/month variable when grouping entries by date
ThreadText: # Need to access year/month variable when grouping entries by date
  
  (Asked by: username_0 on 2015-01-09)
  
  Having issues trying to access the year & month variable when grouping entries by month-year. The code is outputting the desired results (ie. December 2014), however I would like to format the url by 'year/month'.
  
  ### Archives
  
  Browse news & articles for the last year.
  
  ```
  {% set allEntries = craft.entries.section('news').limit(null) %}
  <ul>
  {% for date, entries in allEntries | group('postDate|date("F Y")') %}
      <li><a href="{{ year }}/{{ month }}">{{ date }}</a></li>
  {% endfor %}
  </ul>
  
  ```
  
  **Tags:** entries, group
  
  > **Comments:**
  > **username_0**: Both answers give me the desired results. Now I'm wondering what is the better answer? username_2's splits the `date` variable and username_3 use the DateTime object  
  > **username_1**: Douglass is on the right track. You can *get* a DateTime to [re]format if you your year-month variable is in a format the `date` filter recognizes. I added a code snippet that I hope illustrates this helpfully.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2015-01-10. Score: 10 | Accepted answer
  
  If I understand your example correctly, a simple hyphen would do the trick — "YYYY-MM" is a format the `date` filter recognizes.
  
  ```
  {% set entries = ... %}
  {% set entriesByMonth = entries|group('postDate|date("Y-m")') %}
  {% for month, entries in entriesByMonth %}
    <li>
        <a href="{{ month|date("Y") }}/{{ month|date("m") }}">
          {{ entries | length }} entries in {{ month|date("F Y") }}
        </a>
    </li>
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: I actually like Micahel's answer the best as there is no extra variables needed.  
  
  ---
  
  ### Answer by username_2 on 2015-01-09. Score: 4
  
  The `year` and `month` variables are not defined, so you'd first have to get these from the 'date' variable.
  
  You could do this by using Twig's `split` function and splitting `date` by the space in between:
  
  ```
  {% set dateParts = date | split(' ') %}
  {% set month = dateParts[1] %}
  {% set year = dateParts[0] %}
  
  <a href="{{ year }}/{{ month }}">{{ date }}</a>
  
  ```
  
  
  ---
  
  ### Answer by username_3 on 2015-01-09. Score: 1
  
  I was going to suggest using twig's `date` filter to format the date as needed, but as username_2 astutely pointed out in his comment, you don't really have a dateTime variable to work with.
  
  So my answer is use username_2's answer. ;)
  
  > **Comments:**
  > **username_2**: username_3, am I wrong or is `date` a string, not a DateTime object?  
  > **username_3**: It is. I noticed it as soon as I posted and fixed it. Thanks  
  > **username_2**: username_3, this wouldn't work. Your `entry` variable now contains all entries, so you wouldn't be able to get a `postDate` from it ;)  
  > **username_3**: You're right username_2! Remind me never to answer questions before my first cup of coffee please.  
  > **username_2**: Coffee? Just finishing my first glass of whisky ;)  
  
  ---
  
  