DATEDIFF无法在Symfony2中运行

Has*_*P A 10 php mysql symfony

我无法在symfony2存储库中使用DATEDIFF和CURRENT_TIME.当我使用年份函数时,同样的问题就在那里.为什么会发生这种情况?

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);
Run Code Online (Sandbox Code Playgroud)

如果我没有使用上述功能,此查询正常工作

Jav*_*vad 29

根据链接(DQL函数)DATEDIFF定义并在Doctrine中有效,只需要将其更改DATEDIFF(expr1, expr2)DATE_DIFF(expr1, expr2).
此外,如果您的字段是日期时间字段,则最好使用CURRENT_DATE()而不是NOW()CURRENT_TIME()