Answers.Body: <p>What an idiot.</p>
  <p>I almost never use Advanced element queries which is why it never popped into my head I guess.</p>
  <p>So you can add where() and orWhere() into your standard craft.entries calls.</p>
  <p>So my code becomes</p>
  <pre><code>{% if craft.app.request.getParam('departure') | length %}
      {% for dept in craft.app.request.getParam('departure') %}
          {% set lastDay = dept [0:7] %}
          {% set lastDay = lastDay ~ '-31' %}
          {% set firstDay = dept %}
          {% set entries = entries.orWhere(
              ['between', 'field_startsOn', &quot;#{firstDay}&quot;, &quot;#{lastDay}&quot; ]
          ) %}
      {% endfor %}
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-18T11:26:18.997Z
Answers.LastActivityDate: 2021-02-18T11:26:18.997Z
Answers.UserDisplayName: John
Body: <p>I've got a front end form where a user can select multiple months to find entries with dates in those months.</p>
  <p>I had code that does that for one month, but now I need to expand that to multiple months.</p>
  <pre><code>{# craft.app.request.getParam('departure') format is going to yyyy-mm-dd #}
  
  {% if craft.app.request.getParam('departure') | length %}
      {% set lastDay = craft.app.request.getParam('departure') [0:7] %}
      {% set lastDay = lastDay ~ '-31' %}
      {% set firstDay = craft.app.request.getParam('departure') %}
      {% set entries = entries.startsOn(['and', '&gt;= '~firstDay, '&lt; '~ lastDay]) %}
  {% endif %}
  </code></pre>
  <p>I was trying to combine it as I have with other fields like so:</p>
  <pre><code> {% set deptDates = [] %}
      {% set deptDates = deptDates|merge(['or']) %}
      {% for dept in craft.app.request.getParam('departure') %}
  
          {% set lastDay = dept [0:7] %}
          {% set lastDay = lastDay ~ '-31' %}
          {% set firstDay = dept %}
          {% set deptDates = deptDates|merge(['and', '&gt;= '~firstDay, '&lt; '~ lastDay]) %}
  
      {% endfor %}
      {% set entries = entries.startsOn(deptDates) %}
  </code></pre>
  <p>But, for obvious reasons, this didn't work :)</p>
  <p>Any ideas gratefully received!</p>
  
Tags: <entries><datetime>
Title: Find entries with multiple start and end dates from the same date field
ThreadText: # Find entries with multiple start and end dates from the same date field
  
  (Asked by: username_0 on 2021-02-17)
  
  I've got a front end form where a user can select multiple months to find entries with dates in those months.
  
  I had code that does that for one month, but now I need to expand that to multiple months.
  
  ```
  {# craft.app.request.getParam('departure') format is going to yyyy-mm-dd #}
  
  {% if craft.app.request.getParam('departure') | length %}
      {% set lastDay = craft.app.request.getParam('departure') [0:7] %}
      {% set lastDay = lastDay ~ '-31' %}
      {% set firstDay = craft.app.request.getParam('departure') %}
      {% set entries = entries.startsOn(['and', '>= '~firstDay, '< '~ lastDay]) %}
  {% endif %}
  
  ```
  
  I was trying to combine it as I have with other fields like so:
  
  ```
   {% set deptDates = [] %}
      {% set deptDates = deptDates|merge(['or']) %}
      {% for dept in craft.app.request.getParam('departure') %}
  
          {% set lastDay = dept [0:7] %}
          {% set lastDay = lastDay ~ '-31' %}
          {% set firstDay = dept %}
          {% set deptDates = deptDates|merge(['and', '>= '~firstDay, '< '~ lastDay]) %}
  
      {% endfor %}
      {% set entries = entries.startsOn(deptDates) %}
  
  ```
  
  But, for obvious reasons, this didn't work :)
  
  Any ideas gratefully received!
  
  **Tags:** entries, datetime
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-02-18. Score: 2
  
  What an idiot.
  
  I almost never use Advanced element queries which is why it never popped into my head I guess.
  
  So you can add where() and orWhere() into your standard craft.entries calls.
  
  So my code becomes
  
  ```
  {% if craft.app.request.getParam('departure') | length %}
      {% for dept in craft.app.request.getParam('departure') %}
          {% set lastDay = dept [0:7] %}
          {% set lastDay = lastDay ~ '-31' %}
          {% set firstDay = dept %}
          {% set entries = entries.orWhere(
              ['between', 'field_startsOn', "#{firstDay}", "#{lastDay}" ]
          ) %}
      {% endfor %}
  {% endif %}
  
  ```
  
  
  ---
  
  