<p>Sounds to me like you need to use the Twig <a href="http://twig.sensiolabs.org/doc/filters/format.html" rel="nofollow noreferrer">format</a> filter, I have helped another user out with it <a href="https://craftcms.stackexchange.com/questions/5111/how-do-i-format-the-date-and-time-i-got-from-an-entry/5112#5112">here</a>.</p>

<p>So if you want to output the month as a name (January, February etc), you can use this:</p>

<pre><code>&lt;h2&gt;{{ entry.entryDate|format('F') }}&lt;/h2&gt;
</code></pre>

CC BY-SA 3.0
2015-09-04T16:31:15.263Z
no that breaks it and nothing shows. Which is why I am struggling with this since yesterday now.
Rockwell Rice
CC BY-SA 3.0
2015-09-06T21:55:21.183Z
Probably a typo but it should be ``{{entry.entryDate.format('F')}}``... note the dot instead of the pipe to call format(). If you use the pipe, you're calling Twig's ``format`` filter (which is like printf). If you use ``.format()`` you're calling Craft's internal method which functions like Twig's ``date()``.
RitterKnight
CC BY-SA 3.0
2015-09-08T13:25:47.783Z
So every time (including your code above) I try to format that code inside the h2 it breaks. Dot or pipe, both break it and nothing shows.
Rockwell Rice
CC BY-SA 3.0
2015-09-04T08:08:31.400Z
2015-09-04T08:08:31.400Z
2017-04-13T12:50:59.930Z
Jamie Wade
<p>You are using <code>entry</code> for two different things. <code>&lt;h2&gt;{{entry.entryDate|date('M')}}&lt;/h2&gt;</code> is the entry for the page, and will always be the same. <code>&lt;p&gt;{{entry.entryDate.month}}...</code> is the current entry in <code>entriesInMonth</code>, and will be different each time through the loop.</p>

<p>Here is your current code with some of the html removed for simplicity, and some of the variable names changed for clarity:</p>

<pre><code>{% set allTours = craft.entries.section('tours').find() %}
{% set allToursByMonth = allTours|group('entryDate.month') %}

{% for month, toursInMonth in allToursByMonth %}
    {# this entry will be the same every time around the loop #}
    &lt;h2&gt;{{entry.entryDate|date('M')}}&lt;/h2&gt;
    {% for tour in toursInMonth %}
        &lt;p&gt;{{tour.entryDate.month}}.{{tour.entryDate.day}}.{{tour.entryDate.year}}&amp;nbsp;&amp;nbsp;-&amp;nbsp;&amp;nbsp;{{tour.locationCity}}, {{tour.locationState}}&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href="/tours/{{tour.slug}}" class="btn btn-primary btn-md" style="float:right;"&gt;register&lt;/a&gt;&lt;/p&gt;
    {% endfor %}        
{% endfor%}
</code></pre>

<p>Probably what you want to display in that <code>&lt;h2&gt;</code> is the current <code>month</code> from the outer <code>for</code> loop:</p>

<pre><code>&lt;h2&gt;{{month|date('M')}}&lt;/h2&gt;
</code></pre>

CC BY-SA 3.0
2015-09-04T20:35:54.147Z
You are correct with what I am trying to do, however with your code (or any variations of it that I have tried) it still shows same month for each section.  I added a picture so you can see what I am getting.
Rockwell Rice
CC BY-SA 3.0
2015-09-04T21:03:24.777Z
@RockwellRice your key in `{% for month, toursInMonth in allToursByMonth %}` is already formatted. Change `<h2>{{entry.entryDate|date('M')}}</h2>` to `<h2>{{ month )}}</h2>` and you should be good.
carlcs
CC BY-SA 3.0
2015-09-04T22:05:28.587Z
All that does is output the number, I need to format it to display the text.  So, back to the original question of how do I format that to display the date in text.
Rockwell Rice
CC BY-SA 3.0
2015-09-06T19:12:10.850Z
That broke the grouping and only displayed the date as a number.
Rockwell Rice
CC BY-SA 3.0
2015-09-04T20:22:36.300Z
2015-09-04T20:22:36.300Z
Marion Newlevant
<p>Unsure if you still need this, but I found a workaround for your issue.
I was also having the same issue when formatting it either broke the output using a filter on the formatted month or it just showed 'January'.</p>

<p>My code was initially similar to yours and I used the '|date('F')' filter on the initial entry postdate to show the month name. </p>

<p>Try and change this part of your output:</p>

<pre><code>{{entry.entryDate.month}}
</code></pre>

<p>to</p>

<pre><code>{{entry.entryDate|date('F')}}
</code></pre>

<p>Hopefully this works for you too.</p>

CC BY-SA 3.0
2016-02-22T20:54:37.993Z
2016-02-22T20:54:37.993Z
Shaun Hall
<p>I would suggest to already format entryDate within the <code>group</code> filter in the way you actually want to output it later.
To do that use Twig's <a href="http://twig.sensiolabs.org/doc/filters/date.html" rel="nofollow"><code>date</code></a> filter (→ see all possible <a href="http://php.net/manual/en/function.date.php" rel="nofollow">formatting options</a>).</p>

<pre><code>{% set allEntries = craft.entries.section('tours').find() %}
{% set allEntriesByMonth = allEntries|group('entryDate|date("F")') %}

{% for month, entriesInMonth in allEntriesByMonth %}
    &lt;h2&gt;{{ month }}&lt;/h2&gt;

    {% for entry in entriesInMonth %}
        &lt;div&gt;{{ entry.entryDate|date('m.d.Y') }}&lt;/div&gt;
    {% endfor %}
{% endfor%}
</code></pre>

CC BY-SA 3.0
2015-09-06T19:58:01.843Z
2015-09-06T19:58:01.843Z
carlcs
<p>I have events that are presented by month.  Right now they are being separated by Month but the heading for each chunk shows January as the month for each one.  Not sure why, or how to fix it, am interested in understanding both.  I am somewhat new to craft.  </p>

<pre><code> &lt;div class="container"&gt;

{% if entry.heading is defined %}&lt;h1&gt;{{ entry.heading }}&lt;/h1&gt;{% endif %}

{% set allEntries = craft.entries.section('tours').find() %}
{% set allEntriesByMonth = allEntries|group('entryDate.month') %}

{% for month, entriesInMonth in allEntriesByMonth %}
    &lt;h2&gt;{{entry.entryDate|date('M')}}&lt;/h2&gt;
        {% for entry in entriesInMonth %}
            &lt;div class="row" style="padding-bottom: 25px;"&gt;
                &lt;div class="col-md-12"&gt;

                    &lt;div style="border-bottom: 1px solid #d4d4d4;width:100%;"&gt;
                        &lt;p&gt;{{entry.entryDate.month}}.{{entry.entryDate.day}}.{{entry.entryDate.year}}&amp;nbsp;&amp;nbsp;-&amp;nbsp;&amp;nbsp;{{entry.locationCity}}, {{entry.locationState}}&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href="/tours/{{entry.slug}}" class="btn btn-primary btn-md" style="float:right;"&gt;register&lt;/a&gt;&lt;/p&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        {% endfor %}        
{% endfor%}
</code></pre>

<p></p>

<p>I am trying to adjust the <code>h2</code> with <code>|date('M')</code> in order to display the date as text.  If I do not do that it displays the correct month number, but when I try to format it it breaks and displays the same month for all entries even though it is still ordering them.  So how can I format this to show month as text without breaking it?</p>

<p>Any attempt to format the date breaks it. The dates below should be september and october.</p>

<p><a href="https://i.sstatic.net/pR9iU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/pR9iU.png" alt="enter image description here"></a></p>

CC BY-SA 3.0
2015-09-03T20:52:42.960Z
it is the name of the field that the event happens on, it is set when creating the entry
Rockwell Rice
CC BY-SA 3.0
2015-09-03T20:53:41.503Z
How is the output from `entry.entryDate` formatted? Maybe the output isn't what the date filter expects?
megatrond
<templating><datetime>
How to properly format this date
# How to properly format this date

(Asked by: username_0 on 2015-09-03)

I have events that are presented by month.  Right now they are being separated by Month but the heading for each chunk shows January as the month for each one.  Not sure why, or how to fix it, am interested in understanding both.  I am somewhat new to craft.  
 

{% if entry.heading is defined %}{{ entry.heading }}{% endif %}

{% set allEntries = craft.entries.section('tours').find() %}
{% set allEntriesByMonth = allEntries|group('entryDate.month') %}

{% for month, entriesInMonth in allEntriesByMonth %}
    {{entry.entryDate|date('M')}}
        {% for entry in entriesInMonth %}
            
                

                    
                        {{entry.entryDate.month}}.{{entry.entryDate.day}}.{{entry.entryDate.year}}  -  {{entry.locationCity}}, {{entry.locationState}}   register
                    
                
            
        {% endfor %}        
{% endfor%}


I am trying to adjust the h2 with |date('M') in order to display the date as text.  If I do not do that it displays the correct month number, but when I try to format it it breaks and displays the same month for all entries even though it is still ordering them.  So how can I format this to show month as text without breaking it?
Any attempt to format the date breaks it. The dates below should be september and october.

**Tags:** templating, datetime

> **Comments:**
> **username_0**: it is the name of the field that the event happens on, it is set when creating the entry  
> **username_1**: How is the output from `entry.entryDate` formatted? Maybe the output isn't what the date filter expects?  

---

## 4 answers

### Answer by username_5 on 2015-09-06. Score: 4 | Accepted answer

I would suggest to already format entryDate within the group filter in the way you actually want to output it later.
To do that use Twig's date filter (→ see all possible formatting options).
{% set allEntries = craft.entries.section('tours').find() %}
{% set allEntriesByMonth = allEntries|group('entryDate|date("F")') %}

{% for month, entriesInMonth in allEntriesByMonth %}
    {{ month }}

    {% for entry in entriesInMonth %}
        {{ entry.entryDate|date('m.d.Y') }}
    {% endfor %}
{% endfor%}


---

### Answer by username_2 on 2015-09-04. Score: 2

Sounds to me like you need to use the Twig format filter, I have helped another user out with it here.
So if you want to output the month as a name (January, February etc), you can use this:
{{ entry.entryDate|format('F') }}

> **Comments:**
> **username_0**: no that breaks it and nothing shows. Which is why I am struggling with this since yesterday now.  
> **username_3**: Probably a typo but it should be ``{{entry.entryDate.format('F')}}``... note the dot instead of the pipe to call format(). If you use the pipe, you're calling Twig's ``format`` filter (which is like printf). If you use ``.format()`` you're calling Craft's internal method which functions like Twig's ``date()``.  
> **username_0**: So every time (including your code above) I try to format that code inside the h2 it breaks. Dot or pipe, both break it and nothing shows.  

---

### Answer by username_4 on 2015-09-04. Score: 2

You are using entry for two different things. {{entry.entryDate|date('M')}} is the entry for the page, and will always be the same. {{entry.entryDate.month}}... is the current entry in entriesInMonth, and will be different each time through the loop.
Here is your current code with some of the html removed for simplicity, and some of the variable names changed for clarity:
{% set allTours = craft.entries.section('tours').find() %}
{% set allToursByMonth = allTours|group('entryDate.month') %}

{% for month, toursInMonth in allToursByMonth %}
    {# this entry will be the same every time around the loop #}
    {{entry.entryDate|date('M')}}
    {% for tour in toursInMonth %}
        {{tour.entryDate.month}}.{{tour.entryDate.day}}.{{tour.entryDate.year}}  -  {{tour.locationCity}}, {{tour.locationState}}   register
    {% endfor %}        
{% endfor%}

Probably what you want to display in that  is the current month from the outer for loop:
{{month|date('M')}}

> **Comments:**
> **username_0**: You are correct with what I am trying to do, however with your code (or any variations of it that I have tried) it still shows same month for each section.  I added a picture so you can see what I am getting.  
> **username_5**: @RockwellRice your key in `{% for month, toursInMonth in allToursByMonth %}` is already formatted. Change `<h2>{{entry.entryDate|date('M')}}</h2>` to `<h2>{{ month )}}</h2>` and you should be good.  
> **username_0**: All that does is output the number, I need to format it to display the text.  So, back to the original question of how do I format that to display the date in text.  
> **username_0**: That broke the grouping and only displayed the date as a number.  

---

### Answer by username_6 on 2016-02-22. Score: 1

Unsure if you still need this, but I found a workaround for your issue.
I was also having the same issue when formatting it either broke the output using a filter on the formatted month or it just showed 'January'.
My code was initially similar to yours and I used the '|date('F')' filter on the initial entry postdate to show the month name. 
Try and change this part of your output:
{{entry.entryDate.month}}

to
{{entry.entryDate|date('F')}}

Hopefully this works for you too.


---

