<p>Ok, so in the end you’d want your “startDate” custom field parameter to be a string in this format:</p>

<pre><code>'and, &gt;= 2017-08-04T05:00:00+08:00, &lt; 2017-08-11T04:59:59+08:00'
</code></pre>

<p>I’m outputting a format for the dates that includes the time and timezone, so that we are able to define when exactly events are being refreshed. To do that I’m using the <code>date</code> filter (otherwise Twig outputs dates in <code>Y-m-d</code> format).</p>

<p>Here’s how you compose the final string including the value from the Global Set, that I am simply concatenating to a string that I pass into the <code>date_modify</code> filter.</p>

<pre><code>{% set var = myGlobalSet.myNumbersField %}

{% set rangeStart = now|date_modify('5:00')|date('c') %}
{% set rangeEnd = now|date_modify('5:00 +' ~ var ~ ' weeks')|date('c') %}

{% set startDateParam = 'and, &gt;=' ~ rangeStart ~ ', &lt;' ~ rangeEnd %}
</code></pre>

CC BY-SA 3.0
2017-06-08T16:24:45.380Z
Cool! Thanks. Just to help me understand, are the ('5:00') and the date|('c') setting the time zone?
Brian Rivet
CC BY-SA 3.0
2017-06-08T16:27:52.340Z
Yeah, `date_modify('5:00')` overrides the time and set it to 5:00. `date('c')` outputs the DateTime object in ISO8601 format, the one I posted above which has timezone info included.
carlcs
CC BY-SA 3.0
2017-06-08T16:32:30.210Z
ok so if I don't want to override the time to 5:00 and use the time set on the event I just leave off the date_modify('5:00')?
Brian Rivet
CC BY-SA 3.0
2017-06-08T17:00:40.010Z
It’s the `now` time that is being overridden, but yep you don’t need to do it and it will immediately hide events as soon as they started.
carlcs
CC BY-SA 3.0
2017-06-08T16:21:05.580Z
2017-06-08T16:31:29.907Z
2017-06-08T16:31:29.907Z
carlcs
<pre><code>{% set params = {
      section : 'events',
      order : 'eventStartDate asc',
      eventStartDate : '&gt;=' ~ now,
      limit : row.itemsPerPage.value
} %}
</code></pre>

<p>I am trying to pull a set of event entries for a basic event calendar and I'm trying to figure out the syntax for the eventStartDate parameter to have it pull starting with the current date and ending with a value of the current date + 1 month, 3 months, or 6 months depending on the value set in another field named eventDateRange. I need help with how to write that as a command like the one listed above. </p>

<templating><elementcriteriamodel><datetime>
How can I get entries where a date is within a dynamic date range?
# How can I get entries where a date is within a dynamic date range?

(Asked by: username_0 on 2017-06-08)

{% set params = {
      section : 'events',
      order : 'eventStartDate asc',
      eventStartDate : '>=' ~ now,
      limit : row.itemsPerPage.value
} %}

I am trying to pull a set of event entries for a basic event calendar and I'm trying to figure out the syntax for the eventStartDate parameter to have it pull starting with the current date and ending with a value of the current date + 1 month, 3 months, or 6 months depending on the value set in another field named eventDateRange. I need help with how to write that as a command like the one listed above.

**Tags:** templating, elementcriteriamodel, datetime


---

## 1 answers

### Answer by username_1 on 2017-06-08. Score: 2

Ok, so in the end you’d want your “startDate” custom field parameter to be a string in this format:
'and, >= 2017-08-04T05:00:00+08:00, < 2017-08-11T04:59:59+08:00'

I’m outputting a format for the dates that includes the time and timezone, so that we are able to define when exactly events are being refreshed. To do that I’m using the date filter (otherwise Twig outputs dates in Y-m-d format).
Here’s how you compose the final string including the value from the Global Set, that I am simply concatenating to a string that I pass into the date_modify filter.
{% set var = myGlobalSet.myNumbersField %}

{% set rangeStart = now|date_modify('5:00')|date('c') %}
{% set rangeEnd = now|date_modify('5:00 +' ~ var ~ ' weeks')|date('c') %}

{% set startDateParam = 'and, >=' ~ rangeStart ~ ', <' ~ rangeEnd %}

> **Comments:**
> **username_0**: Cool! Thanks. Just to help me understand, are the ('5:00') and the date|('c') setting the time zone?  
> **username_1**: Yeah, `date_modify('5:00')` overrides the time and set it to 5:00. `date('c')` outputs the DateTime object in ISO8601 format, the one I posted above which has timezone info included.  
> **username_0**: ok so if I don't want to override the time to 5:00 and use the time set on the event I just leave off the date_modify('5:00')?  
> **username_1**: It’s the `now` time that is being overridden, but yep you don’t need to do it and it will immediately hide events as soon as they started.  

---

