DDC-843: Cannot compare or find date fields #1042

Closed
opened 2026-01-22 12:59:48 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 20, 2010).

Jira issue originally created by user odisey:

Here is my dql (get by getDql() method) after the generation:
SELECT u FROM Entities\Music\Articles u WHERE u.date = 2010-08-30
In the database the field is marked as DATE and has the mentioned value;
No results are returned.

Here is how I generate the dql:
$date = new DateTime($date);
$date = $date->format('Y-m-d');
$date_operator = 'eq';
$qb = $this->doctrine->em->createQueryBuilder();
$qb ->select('u')
->from($class, 'u');
$qb->andWhere($qb->expr()->$date_operator('u.date', $date));

Originally created by @doctrinebot on GitHub (Oct 20, 2010). Jira issue originally created by user odisey: Here is my dql (get by getDql() method) after the generation: SELECT u FROM Entities\Music\Articles u WHERE u.date = 2010-08-30 In the database the field is marked as DATE and has the mentioned value; No results are returned. Here is how I generate the dql: $date = new DateTime($date); $date = $date->format('Y-m-d'); $date_operator = 'eq'; $qb = $this->doctrine->em->createQueryBuilder(); $qb ->select('u') ->from($class, 'u'); $qb->andWhere($qb->expr()->$date_operator('u.date', $date));
admin added the Bug label 2026-01-22 12:59:48 +01:00
admin closed this issue 2026-01-22 12:59:49 +01:00
Author
Owner

@doctrinebot commented on GitHub (Oct 20, 2010):

Comment created by mjh_ca:

This is not a bug. The date value needs to be quoted just like SQL -- i.e.

SELECT u FROM Entities\Music\Articles u WHERE u.date = '2010-08-30'

Or bind it as a parameter

SELECT u FROM Entities\Music\Articles u WHERE u.date = ?1
/** ... **/
$query->setParameter(1, '2010-08-30');
$query->getResult();

To debug these kind of things it is often helpful to do

echo $qb->getQuery()->getSQL(); // this will output the generated SQL
@doctrinebot commented on GitHub (Oct 20, 2010): Comment created by mjh_ca: This is not a bug. The date value needs to be quoted just like SQL -- i.e. ``` SELECT u FROM Entities\Music\Articles u WHERE u.date = '2010-08-30' ``` Or bind it as a parameter ``` SELECT u FROM Entities\Music\Articles u WHERE u.date = ?1 /** ... **/ $query->setParameter(1, '2010-08-30'); $query->getResult(); ``` To debug these kind of things it is often helpful to do ``` echo $qb->getQuery()->getSQL(); // this will output the generated SQL ```
Author
Owner

@doctrinebot commented on GitHub (Oct 20, 2010):

Comment created by odisey:

thank you very much!

@doctrinebot commented on GitHub (Oct 20, 2010): Comment created by odisey: thank you very much!
Author
Owner

@doctrinebot commented on GitHub (Oct 20, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Oct 20, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1042