0

Ok I want to list event entries based on the start date of those events.

I have a route set up which provides the date in the same format as held in the start date field. But trying to compare this with:

{% for entry in craft.entries.section('events').startDate(date) %}

to pull out only entries for the specified date fails as the date variable only holds the date portion of the startDate field i.e. 2015-10-02 and not the time segment.

So is there some way I can format this call so that the comparison is like with like without the time segment. I have tried a few things with filters but nothing is working.

Cheers

5

I'm not 100% sure I'm reading your question correctly, but here goes:

I'm assuming you're getting the date as a string as a route param (maybe you shouldn't call it date though, as that is a function in Twig), I'll call that dateTime here:

{% set dayAfter = date(datetime) | date_modify('+1 day') | date('Y-m-d') %} {% set entries = craft.entries.section('events').startDate(['and', '>= '~datetime, '< '~dayAfter]) %}

What's happening is you get a date, then you add one day to that date, then find all entries that have startDate greater than or equal to the date you're looking for, and less than the day after, thus getting all entries for that particular date.

This might be over engineered though, and there might be a way simpler way to do this...

  • Thanks @megatrond works a treat. Although as you say does seem a little over engineered. – Lettie Oct 4 '15 at 18:13

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.