Find entries with multiple start and end dates from the same date field 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', '&gt;= '~firstDay, '&lt; '~ 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', '&gt;= '~firstDay, '&lt; '~ lastDay]) %}

    {% endfor %}
    {% set entries = entries.startsOn(deptDates) %}

But, for obvious reasons, this didn't work :)
Any ideas gratefully received!
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', &quot;#{firstDay}&quot;, &quot;#{lastDay}&quot; ]
        ) %}
    {% endfor %}
{% endif %}