Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DATEDIFF not working in Symfony2

Tags:

php

mysql

symfony

I am not able to use DATEDIFF and CURRENT_TIME in symfony2 repository. Same problem is there while I am using year function..why this is happening?

return $this->getEntityManager()
                            ->createQuery("SELECT u FROM AcmeAdminBundle:AppUsers u  WHERE DATEDIFF(CURRENT_TIME(), u.dob) BETWEEN :fromage AND :toage and u.country = :countries ORDER BY u.id DESC")
                            ->setParameter('fromage', $fromage)
                            ->setParameter('toage', $toage)
                            ->setParameter('countries', $countrystr);

this query working properly if I did not use the above functions

like image 201
Haseena P A Avatar asked Sep 12 '14 10:09

Haseena P A


1 Answers

Base on the link (DQL Functions) the DATEDIFF is defined and is valid in Doctrine just you need to change it from DATEDIFF(expr1, expr2) to DATE_DIFF(expr1, expr2).
Furthermore, if your field is a datetime field it's better to use CURRENT_DATE() instead of NOW() or CURRENT_TIME()

like image 179
Javad Avatar answered Oct 30 '22 21:10

Javad