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

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

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

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

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

CC BY-SA 3.0
2015-10-04T18:13:15.103Z
Thanks @megatrond works a treat. Although as you say does seem a little over engineered.
Lettie
CC BY-SA 3.0
2015-10-03T18:00:47.023Z
2015-10-04T03:21:40.883Z
2015-10-04T03:21:40.883Z
megatrond
<p>Ok I want to list event entries based on the start date of those events.</p>

<p>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:</p>

<pre><code>{% for entry in craft.entries.section('events').startDate(date) %}
</code></pre>

<p>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.</p>

<p>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.</p>

<p>Cheers</p>

<datetime>
How to compare just the date part of a dateTime field?
# How to compare just the date part of a dateTime field?

(Asked by: username_0 on 2015-10-03)

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

**Tags:** datetime


---

## 1 answers

### Answer by username_1 on 2015-10-03. Score: 5 | Accepted answer

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...

> **Comments:**
> **username_0**: Thanks @username_1 works a treat. Although as you say does seem a little over engineered.  

---

