<p>It's difficult to give specific code help without seeing some input/output examples, but here's a go-by:</p>

<p>You can say that an event <em>occurs</em> during a date range if:</p>

<ul>
<li>The event begins before the date range ends</li>
<li><strong>and</strong>, the event ends after the date range begins</li>
</ul>

<p>So, the pseudocode looks something like:</p>

<ul>
<li>Prepare a DateTime representation of the range rangeStartTime (e.g. today at 00:00)</li>
<li>Prepare a DateTime representation of the range rangeEndTime (e.g. tomorrow at 00:00)</li>
<li>For each event, check if the criteria are satisfied: <code>eventStartTime &lt; dayEndTime</code> <strong>and</strong> <code>eventEndTime &gt; dayStartTime</code></li>
<li>If the criteria is satisfied, include the event.</li>
</ul>

<p>So, let's say each of my Event entries has <code>eventStartDate</code> and <code>eventEndDate</code> fields, and I want to list out all the events that <em>occur</em> today <em>(i.e. including, for example, events that started yesterday and end tomorrow)</em>.</p>

<p>I could do something like...</p>

<pre><code>{% set dateRangeStart = today|date('Y-m-d') %}

{% set dateRangeEnd = tomorrow|date('Y-m-d') %}

{% set eventsInRange = craft.entries
    .section('events')
    .eventStartDate('&lt;'~dateRangeEnd)
    .eventEndDate('&gt;'~dateRangeStart)
%}
</code></pre>

<p>Now <code>eventsInRange</code> is an <em>ElementCriteriaModel</em> that finds all Event entries in our date range. And since it's an <em>ElementCriteriaModel</em>, you can plug it into the <code>{% paginate %}</code> tag to get paginated results according to whatever other parameters you desire.</p>

CC BY-SA 3.0
2015-12-15T16:37:35.373Z
2015-12-15T16:48:16.540Z
2015-12-15T16:48:16.540Z
Michael Rog
<p>Thanks @Michael - the difficulty is always going to be introducing some kind of pagination across dates rather than entries. Ended up hacking something together that imitates pagination. Happy to hear any suggestions on improvement, especially in terms of performance/efficiency:</p>

<p><a href="https://gist.github.com/cole007/8fbe1247791985aea3e9" rel="nofollow">https://gist.github.com/cole007/8fbe1247791985aea3e9</a></p>

CC BY-SA 3.0
2015-12-15T17:15:35.863Z
2015-12-15T17:15:35.863Z
Cole Henley
<p>Pulling hair out here so looking for divine inspiration.</p>

<p>Trying to list a set of events/entries grouped by day. This is fine when all the dates are organised by an event date but when we introduce a date span (event start date and event end date) am struggling to work out how to get days that are not specifically occurring on a set day to appear, eg if starts Tuesday and ends Thursday to show on Wednesday. </p>

<p>I can get this working with an arbitrary range, eg to show all the events across a certain month but this gets considerably more complicated introducing pagination when no date range is specified. Ideally need to paginate by dates but pagination requires the ElementCriteriaModel. </p>

<p>Any thoughts on how might go about this as banging head against a brick wall …</p>

<elementcriteriamodel><datetime><pagination>
Showing pagination for a date range of entries
# Showing pagination for a date range of entries

(Asked by: username_0 on 2015-12-15)

Pulling hair out here so looking for divine inspiration.

Trying to list a set of events/entries grouped by day. This is fine when all the dates are organised by an event date but when we introduce a date span (event start date and event end date) am struggling to work out how to get days that are not specifically occurring on a set day to appear, eg if starts Tuesday and ends Thursday to show on Wednesday.

I can get this working with an arbitrary range, eg to show all the events across a certain month but this gets considerably more complicated introducing pagination when no date range is specified. Ideally need to paginate by dates but pagination requires the ElementCriteriaModel.

Any thoughts on how might go about this as banging head against a brick wall …

**Tags:** elementcriteriamodel, datetime, pagination

---

## 2 answers

### Answer by username_1 on 2015-12-15. Score: 3

It's difficult to give specific code help without seeing some input/output examples, but here's a go-by:
You can say that an event occurs during a date range if:

The event begins before the date range ends
and, the event ends after the date range begins

So, the pseudocode looks something like:

Prepare a DateTime representation of the range rangeStartTime (e.g. today at 00:00)
Prepare a DateTime representation of the range rangeEndTime (e.g. tomorrow at 00:00)
For each event, check if the criteria are satisfied: eventStartTime < dayEndTime and eventEndTime > dayStartTime
If the criteria is satisfied, include the event.

So, let's say each of my Event entries has eventStartDate and eventEndDate fields, and I want to list out all the events that occur today (i.e. including, for example, events that started yesterday and end tomorrow).
I could do something like...
{% set dateRangeStart = today|date('Y-m-d') %}

{% set dateRangeEnd = tomorrow|date('Y-m-d') %}

{% set eventsInRange = craft.entries
    .section('events')
    .eventStartDate('<'~dateRangeEnd)
    .eventEndDate('>'~dateRangeStart)
%}

Now eventsInRange is an ElementCriteriaModel that finds all Event entries in our date range. And since it's an ElementCriteriaModel, you can plug it into the {% paginate %} tag to get paginated results according to whatever other parameters you desire.


---

### Answer by username_0 on 2015-12-15. Score: 0

Thanks @Michael - the difficulty is always going to be introducing some kind of pagination across dates rather than entries. Ended up hacking something together that imitates pagination. Happy to hear any suggestions on improvement, especially in terms of performance/efficiency:

<https://gist.github.com/cole007/8fbe1247791985aea3e9>


---

