[英]DATEDIFF not working in Symfony2
I am not able to use DATEDIFF and CURRENT_TIME in symfony2 repository. 我无法在symfony2存储库中使用DATEDIFF和CURRENT_TIME。 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)
. 根据链接( DQL函数 )定义DATEDIFF
并在Doctrine中有效,只需将其从DATEDIFF(expr1, expr2)
更改为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()
此外,如果您的字段是日期时间字段,最好使用CURRENT_DATE()
而不是NOW()
或CURRENT_TIME()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.