Answers.Body: <p>You need to query using strings and your condition should be written as follow:</p>
  <pre><code>{% set catYear = craft.app.request.segment(-1) %}
  
  {% set firstDayOfYear = catYear ~ &quot;-01-01&quot; %}
  {% set lastDayOfYear = catYear ~ &quot;-12-31&quot; %}
  
  
  {% set params = {
      section : 'termine',
      datumTermin : ['and', '&gt;=' ~ firstDayOfYear, '&lt;= ' ~ lastDayOfYear]
  } %}
  
  {% set beitrage = craft.entries(params).all %}
  </code></pre>
  <p><a href="https://craftcms.com/docs/3.x/date-time-fields.html#querying-elements-with-date-fields" rel="nofollow noreferrer">See documentation for reference</a> :)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-04T23:03:28.373Z
Answers.Text: I tested your code in my environment. It works.
Answers.UserDisplayName: thomas
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-08T16:14:36.123Z
Answers.Text: @thomas I deleted your answer since it wasn’t an answer and converted it to a comment here. If Oli’s answer solved the problem for you, please consider accepting it.
Answers.UserDisplayName: Matt Stein
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-04T13:52:11.843Z
Answers.LastActivityDate: 2020-12-04T13:52:11.843Z
Answers.UserDisplayName: Oli
Answers.Body: <p><strong>Bonus Answer:</strong> You can use after and before for that as well like below code.</p>
  <pre><code>{% set catYear = craft.app.request.segment(-1) %}
  
  {% set firstDayOfYear = catYear ~ &quot;-01-01&quot; %}
  {% set firstDayOfNextYear = firstDayOfYear | date_modify('+1 year') %}
  {% set beitrage = craft.entries.after(firstDayOfYear|atom).before(firstDayOfNextYear|atom).all %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-22T10:26:04.017Z
Answers.LastActivityDate: 2020-12-22T10:26:04.017Z
Answers.UserDisplayName: ZealousWeb
Body: <p>I want to output all entries which match with a given year from a custom date field. The year is a string I get from slug. I am using Craft 3.5.16. What did I do wrong?</p>
  <pre><code>{% set catYear = craft.app.request.segment(-1) %}
  
  {% set firstDayOfYear = now | date_modify('1 January ' ~ catYear) %}
  {% set lastDayOfYear = now | date_modify('31 December ' ~ catYear) %}
  
  {% set params = {
    section : 'termine',
    datumTermin : 'and, &gt;= ' ~ firstDayOfYear|date ~ ', &lt;= ' ~ lastDayOfYear|date
  } %}
  
  {% set beitrage = craft.entries(params).all %}
  </code></pre>
  
Tags: <craft3>
Title: Filter Entries by Custom date
ThreadText: # Filter Entries by Custom date
  
  (Asked by: username_0 on 2020-12-04)
  
  I want to output all entries which match with a given year from a custom date field. The year is a string I get from slug. I am using Craft 3.5.16. What did I do wrong?
  
  ```
  {% set catYear = craft.app.request.segment(-1) %}
  
  {% set firstDayOfYear = now | date_modify('1 January ' ~ catYear) %}
  {% set lastDayOfYear = now | date_modify('31 December ' ~ catYear) %}
  
  {% set params = {
    section : 'termine',
    datumTermin : 'and, >= ' ~ firstDayOfYear|date ~ ', <= ' ~ lastDayOfYear|date
  } %}
  
  {% set beitrage = craft.entries(params).all %}
  
  ```
  
  **Tags:** craft3
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-12-04. Score: 3
  
  You need to query using strings and your condition should be written as follow:
  
  ```
  {% set catYear = craft.app.request.segment(-1) %}
  
  {% set firstDayOfYear = catYear ~ "-01-01" %}
  {% set lastDayOfYear = catYear ~ "-12-31" %}
  
  {% set params = {
      section : 'termine',
      datumTermin : ['and', '>=' ~ firstDayOfYear, '<= ' ~ lastDayOfYear]
  } %}
  
  {% set beitrage = craft.entries(params).all %}
  
  ```
  
  [See documentation for reference](https://craftcms.com/docs/3.x/date-time-fields.html#querying-elements-with-date-fields) :)
  
  > **Comments:**
  > **username_0**: I tested your code in my environment. It works.  
  > **username_2**: @username_0 I deleted your answer since it wasn’t an answer and converted it to a comment here. If Oli’s answer solved the problem for you, please consider accepting it.  
  
  ---
  
  ### Answer by username_3 on 2020-12-22. Score: 0
  
  **Bonus Answer:** You can use after and before for that as well like below code.
  
  ```
  {% set catYear = craft.app.request.segment(-1) %}
  
  {% set firstDayOfYear = catYear ~ "-01-01" %}
  {% set firstDayOfNextYear = firstDayOfYear | date_modify('+1 year') %}
  {% set beitrage = craft.entries.after(firstDayOfYear|atom).before(firstDayOfNextYear|atom).all %}
  
  ```
  
  
  ---
  
  