I have a list of events which should list each event until midnight of said day.

So If a gig happens at 17:00 it should still be visible until midnight of the same day.

I came relatively close (I guess) but it's not working:

{% set nocturne = now|date_modify('today 00:00') %}
{% set midnight = nocturne|date('Y-m-d H:i') %}

This should set {{ midnight }} to midnight of the current day.

Then I translate the custom date field of each gig into the same format as {{ mdinight }}

{% set getFirstGig = craft.entries.section('gigEntry').first() %}
{% set gigDate = getFirstGig.konzertDatum|date('Y-m-d H:i') %}

Then I want to call the whole thing:

 {% set upcoming = craft.entries.section('gigEntry').gigDate('>= ' ~midnight) %}
 {% for entry in upcoming %}
   <h2>{{ entry.title }}</h2>
 {% endfor %}

The code actualy works but my test entry with the time 17:00 is not displayed here. What am I missing? And is there a neater way of writing things?

  • 1
    Could you not just set the expiry date on the event entry? – Andy Dec 4 '15 at 12:16
  • So my client needs to put always two dates per entry? That's counter intuitive. – KSPR Dec 7 '15 at 6:53
  • Fair enough......... – Andy Dec 7 '15 at 11:15
up vote 2 down vote accepted

You would need to pass in "now" unmodified and "date_modify" the value in the database to midnight to do the comparison you're after. Unfortunately that's not possible with an element criteria model.

As already mentioned in the comments, set an expiry date. I have written a plugin to set it automatically:


  • Yeah, I use your plugin now. Thank you – KSPR Dec 10 '15 at 9:35

Have you tried?:

 {% set upcoming = craft.entries.section('gigEntry').status('pending', 'live').gigDate('>= ' ~midnight) %}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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