Criteria works with DateTime arrays, but not DateTime objects #6884

Open
opened 2026-01-22 15:40:43 +01:00 by admin · 0 comments
Owner

Originally created by @andreas-aeschlimann on GitHub (Dec 6, 2021).

Bug Report

Q A
BC Break yes/no
Version 2.9

Summary

In my project, I am creating generic queries. I noticed that Criteria::expr()->eq("expiration", new DateTime()) does not work and throws the error Object of class DateTime could not be converted to string. But oddly enough, Criteria::expr()->in("expiration", [new DateTime()]) is working.

I think the behavior should always be the same.

Note: Passing a string does not work either, it then says Could not convert PHP value '2021-09-16 00:05:50' of type 'string' to type 'datetime'. Expected one of the following types: null, DateTime.

Current behavior

See above

How to reproduce

See above

Expected behavior

It would be great if also non-array DateTimes could be used as criteria.

Originally created by @andreas-aeschlimann on GitHub (Dec 6, 2021). ### Bug Report | Q | A |------------ | ------ | BC Break | yes/no | Version | 2.9 #### Summary In my project, I am creating generic queries. I noticed that `Criteria::expr()->eq("expiration", new DateTime())` does not work and throws the error `Object of class DateTime could not be converted to string`. But oddly enough, `Criteria::expr()->in("expiration", [new DateTime()])` is working. I think the behavior should always be the same. Note: Passing a string does not work either, it then says `Could not convert PHP value '2021-09-16 00:05:50' of type 'string' to type 'datetime'. Expected one of the following types: null, DateTime`. #### Current behavior See above #### How to reproduce See above #### Expected behavior It would be great if also non-array DateTimes could be used as criteria.
admin added the Bug label 2026-01-22 15:40:43 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6884