在Doctrine QueryBuilder中表达mysql NOW() [英] Expression mysql NOW() in Doctrine QueryBuilder
本文介绍了在Doctrine QueryBuilder中表达mysql NOW()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在doctrine querybuilder中使用表达式mysql NOW()?
解决方案
在Doctrine2中,您必须使用以下代替 NOW()
。
这样:
CURRENT_TIMESTAMP()
或:
createQuery(...'WHERE x.date =:now')
- > setParameter('now',new \ DateTime('now'))
...
如果您只想要时间或只日期使用其中之一:
CURRENT_TIME()
和 CURRENT_DATE()
How to use the expression mysql NOW() in doctrine querybuilder?
解决方案
In Doctrine2 you have to use one of the following instead of NOW()
.
This:
CURRENT_TIMESTAMP()
Or:
...
createQuery(...'WHERE x.date = :now')
->setParameter('now', new \DateTime('now'))
...
If you want only time or only date use one of those:
CURRENT_TIME()
and CURRENT_DATE()
Documentation can be found here.
这篇关于在Doctrine QueryBuilder中表达mysql NOW()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文