DDC-3573: DateTime objects casted to string when used in aggregate functions in query results #4394

Closed
opened 2026-01-22 14:40:54 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 18, 2015).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user fivejeez:

Similar to DDC-657: [http://www.doctrine-project.org/jira/browse/DDC-657]

DateTime objects are converted to strings when selecting them through an aggregate function.

Example:

    /****
     * @var \DateTime
     * @ORM\Column(name="entryDate", type="datetime")
     */
    private $entryDate;
        $qb = $this->getEntityManager()->createQueryBuilder();
        $qb->select('u.code, max(u.entryDate) as updateDate');
        $qb->from('Update', 'u');
        $qb->addGroupBy('u.code');

        var_dump( $qb->getQuery()->getResult() );

The result contains the date/times as strings not DateTime objects as expected. This affects the query builder. I assume it also affects DQL queries.

Originally created by @doctrinebot on GitHub (Feb 18, 2015). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user fivejeez: Similar to [DDC-657](http://www.doctrine-project.org/jira/browse/DDC-657): [http://www.doctrine-project.org/jira/browse/[DDC-657](http://www.doctrine-project.org/jira/browse/DDC-657)] DateTime objects are converted to strings when selecting them through an aggregate function. Example: ``` /**** * @var \DateTime * @ORM\Column(name="entryDate", type="datetime") */ private $entryDate; ``` ``` $qb = $this->getEntityManager()->createQueryBuilder(); $qb->select('u.code, max(u.entryDate) as updateDate'); $qb->from('Update', 'u'); $qb->addGroupBy('u.code'); var_dump( $qb->getQuery()->getResult() ); ``` The result contains the date/times as strings not DateTime objects as expected. This affects the query builder. I assume it also affects DQL queries.
admin added the New FeatureCan't Fix labels 2026-01-22 14:40:54 +01:00
admin closed this issue 2026-01-22 14:40:54 +01:00
Author
Owner

@agarb7 commented on GitHub (Apr 11, 2018):

Is it bug or behavior by design?

@agarb7 commented on GitHub (Apr 11, 2018): Is it bug or behavior by design?
Author
Owner

@Ocramius commented on GitHub (Apr 11, 2018):

max(u.entryDate) as updateDate means apply function MAX() to updateDate, which may really produce anything.
Function return values are never really converted to anything, as we can't predict any type transformations happening in there.

@Ocramius commented on GitHub (Apr 11, 2018): `max(u.entryDate) as updateDate` means `apply function MAX() to updateDate`, which may really produce anything. Function return values are never really converted to anything, as we can't predict any type transformations happening in there.
Author
Owner

@Ocramius commented on GitHub (Apr 11, 2018):

Closing as can't fix

@Ocramius commented on GitHub (Apr 11, 2018): Closing as `can't fix`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4394