After spending a lot of time solving this for myself I thought I'd share it. In my Craft 2 template I had this query:

{% set result = craft.entries({
    section: 'events',
    eventDate: ['and', '<' ~ now.w3c(), '> ' ~ now | date_modify('-6 days')],
    results: ':notempty:',
    order: 'eventDate desc',
    with: ['imageGallery'],
    limit: 3
}) %}

1 Answer 1


My Craft 3 version is:

{% set result = craft.entries()
    .eventDate( ['and', '<' ~ now|atom, '>' ~ now|date_modify('-6 days')|atom ] )
    .orderBy('eventDate desc')

Note the extra |atom after the date_modify('-6 days')

  • The atom filter would work too, so just simplified your example to use that. Also worth noting that batch-setting parameters is still supported, though the chain syntax you’ve switched to is better (gives the query a chance to do normalization on the values). Aug 13, 2018 at 21:34
  • I seem to remember being advised to use the batch setting method in preference in a past SE answer. This caused me some confusion switching my existing Craft 2 code to Craft 3 as all the example code uses the chain syntax.
    – Paul Frost
    Aug 14, 2018 at 7:47
  • It was faster to use the batch method in Craft 2; in Craft 3 it’s a wash either way. Aug 14, 2018 at 11:53

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.