Answers.Body: <p>This should work:</p>
  
  <pre><code>{% set year = '2016' %}
  
  {% set eventEntries = craft.entries
      .section('events')
      .where(['&gt;=','field_eventStartDate',year~'-01-01'])
      .andWhere(['&lt;=','field_eventStartDate',year~'-12-31'])
      .orderBy('eventStartDate asc')
      .limit(12)
  %} 
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-29T18:56:47.830Z
Answers.Text: That did it, Udo.  Thanks so much!
Answers.UserDisplayName: gjhead
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-28T06:48:53.180Z
Answers.LastActivityDate: 2019-06-28T06:48:53.180Z
Answers.UserDisplayName: Udo
Body: <p>I'm passing along a year as the <code>yearQuery</code> variable.  Later in my template, I am doing this:</p>
  
  <pre><code>{% set eventEntries = craft.entries
      .section('events')
      .eventStartDate('&gt;=' ~ yearQuery)
      .eventStartDate('&lt;' ~ (yearQuery + 1))
      .orderBy('eventStartDate asc')
      .limit(12)
  %} 
  </code></pre>
  
  <p>What I want to do is show all entries for a year based on the "eventStartDate" field - and not the date they were posted.  </p>
  
  <p>So basically, all Events that were on in 2018, etc.</p>
  
  <p>Is it possible to do this within this query or is there something I am just missing since I have been up way too late?  I have a feeling I may be missing something obvious...</p>
  
Tags: <datetime><query>
Title: Can I query based on a date field rather than the postdate?
ThreadText: # Can I query based on a date field rather than the postdate?
  
  (Asked by: username_0 on 2019-06-28)
  
  I'm passing along a year as the `yearQuery` variable. Later in my template, I am doing this:
  
  ```
  {% set eventEntries = craft.entries
      .section('events')
      .eventStartDate('>=' ~ yearQuery)
      .eventStartDate('<' ~ (yearQuery + 1))
      .orderBy('eventStartDate asc')
      .limit(12)
  %} 
  
  ```
  
  What I want to do is show all entries for a year based on the "eventStartDate" field - and not the date they were posted.
  
  So basically, all Events that were on in 2018, etc.
  
  Is it possible to do this within this query or is there something I am just missing since I have been up way too late? I have a feeling I may be missing something obvious...
  
  **Tags:** datetime, query
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-06-28. Score: 1
  
  This should work:
  
  ```
  {% set year = '2016' %}
  
  {% set eventEntries = craft.entries
      .section('events')
      .where(['>=','field_eventStartDate',year~'-01-01'])
      .andWhere(['<=','field_eventStartDate',year~'-12-31'])
      .orderBy('eventStartDate asc')
      .limit(12)
  %} 
  
  ```
  
  > **Comments:**
  > **username_0**: That did it, Udo.  Thanks so much!  
  
  ---
  
  