DDC-3291: Cannot use eq expression for comparison of DateTime #4072

Open
opened 2026-01-22 14:34:40 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 1, 2014).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user sparrowek:

When I use return ArrayCollection::matching() with criteria defined with eq expression like that:
Criteria::create()->where(Criteria::expr()->eq('day', $day))
I get no results since equality operator uses === comparison which will almost always return false for objects. The only way I found to get around this is to use in operator instead
Criteria::create()->where(Criteria::expr()->in('day', array($day)))

Originally created by @doctrinebot on GitHub (Sep 1, 2014). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user sparrowek: When I use return ArrayCollection::matching() with criteria defined with eq expression like that: `Criteria::create()->where(Criteria::expr()->eq('day', $day))` I get no results since equality operator uses === comparison which will almost always return false for objects. The only way I found to get around this is to use in operator instead `Criteria::create()->where(Criteria::expr()->in('day', array($day)))`
admin added the Bug label 2026-01-22 14:34:40 +01:00
Author
Owner

@jamesmoey commented on GitHub (Sep 16, 2017):

Any plan to add expression to compare date? Or a loose equal == instead of ===

@jamesmoey commented on GitHub (Sep 16, 2017): Any plan to add expression to compare date? Or a loose equal == instead of ===
Author
Owner

@Ocramius commented on GitHub (Sep 16, 2017):

No plans for that, and we won't add exceptions for custom scalar types, such as DateTime, so for now you will need to stick to DQL functions.

@Ocramius commented on GitHub (Sep 16, 2017): No plans for that, and we won't add exceptions for custom scalar types, such as `DateTime`, so for now you will need to stick to DQL functions.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4072