Expression mysql NOW() in Doctrine QueryBuilder

user1906245 picture user1906245 · Dec 16, 2012 · Viewed 25.6k times · Source

How to use the expression mysql NOW() in doctrine querybuilder?

Answer

Mats Rietdijk picture Mats Rietdijk · Dec 17, 2012

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.