在Doctrine QueryBuilder中表达mysql NOW() [英] Expression mysql NOW() in Doctrine QueryBuilder

查看:124
本文介绍了在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆