<p>This is how you fix this:</p>

<pre><code>{# Old code #}
{% for year in now.year .. firstEntryEver.postDate.year %}

{# New code #}
{% for year in now.year .. firstEntryEver.postDate |date('Y') %}
</code></pre>

CC BY-SA 4.0
2018-11-27T15:34:24.077Z
2018-11-27T15:34:24.077Z
Paul
<p>I am trying to work through deprecation warning. I have not touched Craft in a few months, so I am a bit rusty. </p>

<p>The Deprecation Message is:</p>

<blockquote>
  <p>DateTime::year is deprecated. Use the |date('Y') filter instead.</p>
</blockquote>

<p>The offending line is:</p>

<blockquote>
  <p>{% for year in now.year .. firstEntryEver.postDate.year %}   </p>
</blockquote>

<p>Here is the context:</p>

<pre><code>{% set firstEntryEver = craft.entries.section('posts').orderBy('postDate asc').one() %}
{% for year in now.year .. firstEntryEver.postDate.year %}                        
 &lt;a href="/archives/{{ year }}" class="dropdown-item"&gt;
 &lt;i class="material-icons"&gt;date_range&lt;/i&gt; {{ year }}&lt;/a&gt;
 {% endfor %}
</code></pre>

<p>So, how do I fix this?</p>

<templating><error-message>
How do I fix a deprecation error for DateTime::year?
# How do I fix a deprecation error for DateTime::year?

(Asked by: username_0 on 2018-11-27)

I am trying to work through deprecation warning. I have not touched Craft in a few months, so I am a bit rusty. 
The Deprecation Message is:

DateTime::year is deprecated. Use the |date('Y') filter instead.

The offending line is:

{% for year in now.year .. firstEntryEver.postDate.year %}   

Here is the context:
{% set firstEntryEver = craft.entries.section('posts').orderBy('postDate asc').one() %}
{% for year in now.year .. firstEntryEver.postDate.year %}                        
 
 date_range {{ year }}
 {% endfor %}

So, how do I fix this?

**Tags:** templating, error-message


---

## 1 answers

### Answer by username_1 on 2018-11-27. Score: 1 | Accepted answer

This is how you fix this:
{# Old code #}
{% for year in now.year .. firstEntryEver.postDate.year %}

{# New code #}
{% for year in now.year .. firstEntryEver.postDate |date('Y') %}


---

