简体   繁体   中英

Symfony2 / Doctrine2 - get sql min,max date values

My problem is when i want to get the max or the min date value between 2013-04-08,2013-04-07 and 2013-04-06, the response is always 2013-04-08 for the min and the max

my script :

$max_date =     $em ->createQuery("SELECT MAX(p.date) FROM TrackingMarqueBundle:PointdeventeOperateursSaisie p")
                        ->getSingleScalarResult();
    $min_date =     $em ->createQuery("SELECT MIN(p.date) FROM TrackingMarqueBundle:PointdeventeOperateursSaisie p")
                        ->getSingleScalarResult();

Any help please?

Maybe

$em ->createQuery("SELECT MAX(p.date) max_date,MIN(p.date) min_date FROM TrackingMarqueBundle:PointdeventeOperateursSaisie p")->getArrayResult();

I have this code works correctly

doctrine/orm                         v2.5.10

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM