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
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With