<p>I like <strong>conditionals</strong> approach by Victor. Here's the slightly modified version for Craft 2.6:</p>

<pre><code>{% set allEntries = craft.entries.section('blog') %}
{% set last_date = '' %}

{% for entry in allEntries %}
    {% if last_date != entry.postDate|date('Ymd') %}

        This entry is the first of a new day
    {% endif %}

    {% set last_date = entry.postDate|date('Ymd') %}

    {{ entry.title }}
{% endfor %}
</code></pre>

<p>The key (apart from .date being .postDate) is that entry.postDate will render a <em>formatted</em> value like 2017-02-23, however the <em>evaluated</em> value of entry.postDate will be the underlying timestamp, which includes hours/minutes/seconds. This means two entries from the same day may have a postDate that outputs 2017-02-23, but their underlying timestamps will likely have different h/m/s, making comparisons unreliable. Being explicit with postDate output (e.g. 'Ymd', or 20170223) solves the issue. </p>

CC BY-SA 3.0
2017-02-22T23:42:44.053Z
2017-02-22T23:42:44.053Z
user3176488
<p><strong>Group:</strong></p>

<p>Take a look at Craft's custom <a href="http://buildwithcraft.com/docs/templating/filters#group" rel="nofollow">group filter</a>. Your example could look like this:</p>

<pre class="lang-twig prettyprint-override"><code>{% set allEntries = craft.entries.section('blog').find() %}
{% set allEntriesByDay = allEntries | group('postDate') %}

{% for day, entriesInDay in allEntriesByDay %}
    &lt;h1&gt;{{ day }}&lt;/h1&gt;

    {% for entry in entriesInDay %}
        {{ entry.title }}
    {% endfor %}
{% endfor %}
</code></pre>

<p>.</p>

<p><strong>Conditionals:</strong></p>

<p>You could also save the last entries date and use conditionals:</p>

<pre class="lang-twig prettyprint-override"><code>{% set allEntries = craft.entries.section('blog') %}
{% set last_date = '' %}

{% for entry in allEntries %}
    {% if last_date &lt; entry.date %}
        This entry is the first of a new day
    {% endif %}

    {% set last_date = entry.date %}

    {{ entry.title }}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-06-21T16:29:04.263Z
This might be a dumb question... but how do I reformat the {{ day }} variable in your first example? If I do something like:
    {{ day|date("D") }}
It changes every instance to the same date.
Jesse Bennett-Chamberlain
CC BY-SA 3.0
2014-06-21T16:42:30.647Z
@JesseBennett-Chamberlain You're right, my mistake. I accidentally added .day to postDate which means only the numerical value was passed. I edited the answer, it works now.
Victor
CC BY-SA 3.0
2014-06-21T14:59:11.090Z
2014-06-23T14:58:35.450Z
2014-06-23T14:58:35.450Z
Victor
<p>I'm wondering how I would replicate the ExpressionEngine <a href="http://ellislab.com/expressionengine/user-guide/add-ons/channel/channel_entries.html#date-heading" rel="nofollow"><code>date_heading</code></a> tag pair in Craft?</p>

<pre><code>{date_heading}  {entry_date format="%Y %m %d"}  {/date_heading}
</code></pre>

<blockquote>
  <p>The date heading can be used to show a heading at certain intervals.
  The interval can be set to show hourly, daily, weekly, monthly, or
  yearly.</p>
</blockquote>

CC BY-SA 3.0
2014-06-21T14:50:38.500Z
Could you clarify the ultimate goal here? Is it to show entries grouped by dates?
Stuart Whitehead
CC BY-SA 3.0
2014-06-21T15:02:34.987Z
Yep... that's exactly what I'd like to do.
Jesse Bennett-Chamberlain
<date>
How do you replicate the EE {date_heading} tag pair in Craft?
# How do you replicate the EE {date_heading} tag pair in Craft?

(Asked by: username_0 on 2014-06-21)

I'm wondering how I would replicate the ExpressionEngine date_heading tag pair in Craft?
{date_heading}  {entry_date format="%Y %m %d"}  {/date_heading}


The date heading can be used to show a heading at certain intervals.
  The interval can be set to show hourly, daily, weekly, monthly, or
  yearly.

**Tags:** date

> **Comments:**
> **username_1**: Could you clarify the ultimate goal here? Is it to show entries grouped by dates?  
> **username_0**: Yep... that's exactly what I'd like to do.  

---

## 2 answers

### Answer by username_3 on 2014-06-21. Score: 7 | Accepted answer

Group:
Take a look at Craft's custom group filter. Your example could look like this:
{% set allEntries = craft.entries.section('blog').find() %}
{% set allEntriesByDay = allEntries | group('postDate') %}

{% for day, entriesInDay in allEntriesByDay %}
    {{ day }}

    {% for entry in entriesInDay %}
        {{ entry.title }}
    {% endfor %}
{% endfor %}

.
Conditionals:
You could also save the last entries date and use conditionals:
{% set allEntries = craft.entries.section('blog') %}
{% set last_date = '' %}

{% for entry in allEntries %}
    {% if last_date < entry.date %}
        This entry is the first of a new day
    {% endif %}

    {% set last_date = entry.date %}

    {{ entry.title }}
{% endfor %}

> **Comments:**
> **username_0**: This might be a dumb question... but how do I reformat the {{ day }} variable in your first example? If I do something like:     {{ day|date("D") }} It changes every instance to the same date.  
> **username_3**: @JesseBennett-Chamberlain You're right, my mistake. I accidentally added .day to postDate which means only the numerical value was passed. I edited the answer, it works now.  

---

### Answer by username_2 on 2017-02-22. Score: 1

I like conditionals approach by username_3. Here's the slightly modified version for Craft 2.6:
{% set allEntries = craft.entries.section('blog') %}
{% set last_date = '' %}

{% for entry in allEntries %}
    {% if last_date != entry.postDate|date('Ymd') %}

        This entry is the first of a new day
    {% endif %}

    {% set last_date = entry.postDate|date('Ymd') %}

    {{ entry.title }}
{% endfor %}

The key (apart from .date being .postDate) is that entry.postDate will render a formatted value like 2017-02-23, however the evaluated value of entry.postDate will be the underlying timestamp, which includes hours/minutes/seconds. This means two entries from the same day may have a postDate that outputs 2017-02-23, but their underlying timestamps will likely have different h/m/s, making comparisons unreliable. Being explicit with postDate output (e.g. 'Ymd', or 20170223) solves the issue.


---

