Getting error while using interval in doctrine

2019-07-08 18:47发布

When I use below query (Doctrine 2), I was getting error, and can't use INTERVAL in query,

$qb->andWhere("(pv.appointment_date + INTERVAL 48 HOUR) >= UTC_TIMESTAMP()");

Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got '48'"

2条回答
何必那么认真
2楼-- · 2019-07-08 19:29

Doctrine is an ORM which used DQL, it is not same as SQL. Not all functions in the sql are supported by doctine by default. DQL doesn't ships with the support for INTERVAL. For that you have to add user defined functions DQL User Defined Functions.

A complete set of function is available in this git repo DoctrineExtensions

And the above query will become DATE_ADD(pv.appointment_date, INTERVAL 48 HOUR) >= UTC_TIMESTAMP()

查看更多
虎瘦雄心在
3楼-- · 2019-07-08 19:41

If you want to use INTERVAL (in Doctrine 2, DQL) on mysql comumn field, You can use as below,

$qb->andWhere("DATE_ADD(pv.appointmentDate,48,'hour') >= UTC_TIMESTAMP()");

It will print SQL as below,

...... DATE_ADD(p0_.appointmentDate, INTERVAL 48 HOUR) >= UTC_TIMESTAMP() .....
查看更多
登录 后发表回答