我有类似的查询:
$em->createQuery(
'SELECT t FROM myTestBundle:User t WHERE t.userId = :username AND
t.tokenCreatedtime > (NOW() - INTERVAL 800 MINUTE)'
);
(NOW() - INTERVAL 800 MINUTE)
在DQL中无效。有没有其他方法可以实现这个目标?
答案 0 :(得分:2)
我建议您创建一个占位符并传递DateTime
对象
$q = $em->createQuery(
'SELECT t FROM myTestBundle:User t WHERE t.userId = :username AND
t.tokenCreatedtime > :createdTime '
);
$q->setParameter(':createdTime',new \DateTime("-800 minute")
此外,您可能希望将\DateTime
对象创建为new \DateTime("-800 minute")