{% 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.

1 Answer 1


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 %}
  • Cool! Thanks. Just to help me understand, are the ('5:00') and the date|('c') setting the time zone? Commented Jun 8, 2017 at 16:24
  • 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
    Commented Jun 8, 2017 at 16:27
  • 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')? Commented Jun 8, 2017 at 16:32
  • 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
    Commented Jun 8, 2017 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.