Answers.Body: <p>Filtering entries by year with pagination example:</p>
  
  <pre><code>{% set query = craft.request.getQuery() %}
  {% set selectedYear = query.year is defined ? query.year|abs : FALSE %}
  
  {% paginate craft.entries({
     section: 'news',
     postDate: '&gt;=' ~ selectedYear,
     postDate: '&lt;' ~ (selectedYear + 1)
  }).limit(12) as pageInfo, newsEntries %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-06-14T08:36:42.930Z
Answers.Text: This will not work, because the 2nd postDate condition overwrites the first. Try something like that:  
  `postDate: ([ 'and', '>= ' ~ selectedYear, '< ' ~ (selectedYear + 1) ]),`.
  Sorry for the bad code formatting.
Answers.UserDisplayName: Mateng
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-06T13:27:51.200Z
Answers.LastActivityDate: 2017-10-07T08:03:37.027Z
Answers.LastEditDate: 2017-10-07T08:03:37.027Z
Answers.UserDisplayName: denesis
Body: <p>I'm trying to pull all events where the event's year from <code>endDate</code> matches the queried year (<code>yearParam</code>). When I have this, it's pulling in all events before the <code>yearParam</code>:</p>
  
  <pre><code>{% set pastEntries = craft.entries({endDate: '&lt;' ~ yearParam}).section('events').order('endDate desc') %}
  </code></pre>
  
  <p>However, what I'd really like is to get entries that match the <code>yearParam</code> (so if the yearParam is 2017, then any events from 2017 should be pulled in). </p>
  
  <p>Any and all help is greatly appreciated. Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-15T20:17:10.853Z
Comments.Text: If I'm following you correctly, wouldn't `{endDate: '=' ~ yearParam}` or `{endDate: yearParam}` do what you're looking for?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-06-28T14:06:53.377Z
Comments.Text: That did it, @denesis. Thanks!
Comments.UserDisplayName: gjhead
Tags: <entries>
Title: Query entries based on date's year
ThreadText: # Query entries based on date's year
  
  (Asked by: username_0 on 2017-05-15)
  
  I'm trying to pull all events where the event's year from `endDate` matches the queried year (`yearParam`). When I have this, it's pulling in all events before the `yearParam`:
  
  ```
  {% set pastEntries = craft.entries({endDate: '<' ~ yearParam}).section('events').order('endDate desc') %}
  
  ```
  
  However, what I'd really like is to get entries that match the `yearParam` (so if the yearParam is 2017, then any events from 2017 should be pulled in).
  
  Any and all help is greatly appreciated. Thanks!
  
  **Tags:** entries
  
  > **Comments:**
  > **username_1**: If I'm following you correctly, wouldn't `{endDate: '=' ~ yearParam}` or `{endDate: yearParam}` do what you're looking for?  
  > **username_2**: That did it, @username_3. Thanks!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2017-10-06. Score: 2
  
  Filtering entries by year with pagination example:
  
  ```
  {% set query = craft.request.getQuery() %}
  {% set selectedYear = query.year is defined ? query.year|abs : FALSE %}
  
  {% paginate craft.entries({
     section: 'news',
     postDate: '>=' ~ selectedYear,
     postDate: '<' ~ (selectedYear + 1)
  }).limit(12) as pageInfo, newsEntries %}
  
  ```
  
  > **Comments:**
  > **username_4**: This will not work, because the 2nd postDate condition overwrites the first. Try something like that:   `postDate: ([ 'and', '>= ' ~ selectedYear, '< ' ~ (selectedYear + 1) ]),`. Sorry for the bad code formatting.  
  
  ---
  
  