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?

2 Answers 2

2

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')
%}
0

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')
%}
8
  • Hmm, that doesn't seem to work. I'm still getting events starting before the value of {fwd}.
    – 4midori
    Commented Feb 27, 2017 at 15:31
  • Try removing |date('c') from fwd eventStartDate.
    – a-am
    Commented Feb 27, 2017 at 15:32
  • Still not working - is there a way to see the full query the Craft is running?
    – 4midori
    Commented Feb 27, 2017 at 16:58
  • If you have devMode turned on you can view in your JS console what craft is doing.
    – a-am
    Commented Feb 27, 2017 at 17:03
  • Got it - what am I looking for?
    – 4midori
    Commented Feb 27, 2017 at 20:40

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.