2

I have a bunch of entries with field eventStartDate and eventEndDate.

First I set the date

    {% set fwd = entry.eventStartDate|date_modify('+30 min')|date('c') %}

When I output the value of fwd, it is 2017-04-21T08:30:00-05:00

So that's 4/21/2017 at 8:30 AM

Then I query the channel to get events after that date/time

{% set upcomingEvents = craft.entries
  .section('schedule')
  .order('eventStartDate asc')
  .eventStartDate('> ' ~ fwd )
  .limit(5)
  .status('live, pending')
%}

I get events on 4/21/17 starting at 8:00AM, not what I intended.

Is my syntax wrong?

1

Include an and in the date filter with a comma. When boiled down this is treaded as an array then converted to a SQL statement.

{% set upcomingEvents = craft.entries
  .section('schedule')
  .order('eventStartDate asc')
  .eventStartDate('and', '> ' ~ fwd )
  .limit(5)
  .status('live, pending')
%}
  • Hmm, that doesn't seem to work. I'm still getting events starting before the value of {fwd}. – 4midori Feb 27 '17 at 15:31
  • Try removing |date('c') from fwd eventStartDate. – aran Feb 27 '17 at 15:32
  • Still not working - is there a way to see the full query the Craft is running? – 4midori Feb 27 '17 at 16:58
  • If you have devMode turned on you can view in your JS console what craft is doing. – aran Feb 27 '17 at 17:03
  • Got it - what am I looking for? – 4midori Feb 27 '17 at 20:40
1

This code works - I double checked. I had a bug further down in my code.

{% set fwd = entry.eventStartDate|date_modify('+30 min')|date('c') %}

{% set upcomingEvents = craft.entries
  .section('schedule')
  .order('eventStartDate asc')
  .eventStartDate('> ' ~ fwd )
  .limit(5)
  .status('live, pending')
%}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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