<p>After doing a bit more digging, I think the only real option here is run a preliminary query to pull out the ids of the elements I want and then pass that into the ElementCriteriaModel. It's not ideal, but it'll do.</p>

CC BY-SA 3.0
2017-01-10T15:21:00.940Z
2017-01-10T15:21:00.940Z
Michael Witwicki
<p>Working with the <a href="https://github.com/pixelandtonic/ElementAPI" rel="nofollow noreferrer">Element API</a> for the first time and I'm having a bit of a hard time finding any kind of documentation regarding writing more complex conditionals using the <a href="https://craftcms.com/docs/templating/elementcriteriamodel" rel="nofollow noreferrer">ElementCriteriaModel</a>.</p>

<p>What I'm trying to accomplish, is selecting all entries (they are events with a start/end date as custom fields) from a given section, which overlap in any way with a passed-in query start/end date.</p>

<p>It is probably easier to simply supply the raw query that works, and perhaps someone could point me in the direction of documentation that could help me.</p>

<pre><code>SELECT *
FROM craft_content
WHERE
! ( field_eventStartDate &gt; @queryStartDate AND field_eventStartDate &gt; @queryEndDate)
AND
! ( field_eventEndDate &lt; @queryStartDate AND field_eventEndDate &lt; @queryEndDate )
</code></pre>

<elementcriteriamodel><plugin-elementapi>
Complex Conditionals with ElementCriteriaModel / Element API
# Complex Conditionals with ElementCriteriaModel / Element API

(Asked by: username_0 on 2017-01-09)

Working with the Element API for the first time and I'm having a bit of a hard time finding any kind of documentation regarding writing more complex conditionals using the ElementCriteriaModel.
What I'm trying to accomplish, is selecting all entries (they are events with a start/end date as custom fields) from a given section, which overlap in any way with a passed-in query start/end date.
It is probably easier to simply supply the raw query that works, and perhaps someone could point me in the direction of documentation that could help me.
SELECT *
FROM craft_content
WHERE
! ( field_eventStartDate > @queryStartDate AND field_eventStartDate > @queryEndDate)
AND
! ( field_eventEndDate < @queryStartDate AND field_eventEndDate < @queryEndDate )

**Tags:** elementcriteriamodel, plugin-elementapi


---

## 1 answers

### Answer by username_0 on 2017-01-10. Score: 3 | Accepted answer

After doing a bit more digging, I think the only real option here is run a preliminary query to pull out the ids of the elements I want and then pass that into the ElementCriteriaModel. It's not ideal, but it'll do.


---

