Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-27T15:34:24.077Z
Answers.LastActivityDate: 2018-11-27T15:34:24.077Z
Answers.UserDisplayName: Paul
Body: <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>
  
Tags: <templating><error-message>
Title: How do I fix a deprecation error for DateTime::year?
ThreadText: # 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 %}                        
   <a href="/archives/{{ year }}" class="dropdown-item">
   <i class="material-icons">date_range</i> {{ year }}</a>
   {% 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') %}
  
  ```
  
  
  ---
  
  