# Date comparison with datetime & date

**URL:** <https://community.directus.com/t/date-comparison-with-datetime-date/739>\
**Category:** Help\
**Tags:** querying, flows\
**Created:** [July 11, 2025, 1:20pm UTC](https://community.directus.com/t/date-comparison-with-datetime-date/739 "2025-07-11T13:20:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_O](https://sea2.discourse-cdn.com/flex002/user_avatar/community.directus.com/david_o/32/649_2.png) [@David\_O](https://community.directus.com/u/David_O)\
**Post date:** [July 11, 2025, 1:20pm UTC](https://community.directus.com/t/date-comparison-with-datetime-date/739/1 "2025-07-11T13:20:42Z")

</div>

Hey all,

How come this query filter works:

“start\_time”: {  
“\_gte”: “{{$trigger.query.date}}”  
}

\*Where start\_time = datetime and date = 2025-07-11

But this doesn’t?

“start\_time”: {  
“\_eq”: “{{$trigger.query.date}}”  
}

I wouldn’t expect either to work but I’m only trying to filter start\_time’s date == query.date.

Hopefully that makes sense 😬

Any ideas without having to write custom js?

---

<div class="post-metadata">

**Author:** ![bryantgillespie](https://sea2.discourse-cdn.com/flex002/user_avatar/community.directus.com/bryantgillespie/32/33_2.png) [@bryantgillespie](https://community.directus.com/u/bryantgillespie)\
**Post date:** [July 14, 2025, 1:07pm UTC](https://community.directus.com/t/date-comparison-with-datetime-date/739/2 "2025-07-14T13:07:15Z")

</div>

Great question! Yeah, the answers in the comments are spot on.

The **datetime** field type gets cast to a full date and time value, which is why your equal filter didn’t work as expected. When you’re comparing dates, you’re essentially comparing something like `2023-07-14 00:00:00` against `2023-07-14 15:30:22` - they’ll never be equal.

## Solutions

**Option 1: Use the `date` field type**  
If you only need date comparison without time, use the field type `date` instead of `datetime`. This will store just the date portion and make equality comparisons work as expected.

That should allow this syntax to work.

```auto
{
	filter: {
		start_time: {
			_eq: "2025-07-14"
		}
	}
}

```

**Option 2: Use the `between` filter (recommended)**  
For most date comparison scenarios, I really like the `between` filter. It’s super handy for getting all records within a date range.

Here’s a quick example:

```auto
{
	filter: {
		start_time: {
			_between: [
				"2025-07-14T00:00:00Z",
				"2025-07-14T23:59:59Z"
			]
		}
	}
}

```

The alternative form to express this one is a bit more verbose.

```auto
{
	filter: {
		_and: [
			{
				start_time: {
					_gte: "2025-07-14T00:00:00Z"
				}
			},
			{
				end_time: {
					_lte: "2025-07-14T23:59:59Z"
				}
			}
		]
	}
}

```

This gives you everything that happened on July 14th, regardless of the specific time. Just have to make sure you’re matching up your input with what the field type is expecting.

The `between` filter is great for date-based queries - works great for daily, weekly, or monthly reports too! 🤘

P.S. you might also play around with the `$NOW` dynamic variable.

```auto
{
  "datetime": {
    "_lte": "$NOW"
  }
}

```

It’s handy because you can do adjustments as well like `$NOW(-1 year)` or `$NOW(+1 day)`
