Doctrine querybuilder DATE_FORMAT 不起作用
我在 createQueryBuilder 中的 DATE_FORMAT 有一些问题
I'm having some problems with DATE_FORMAT inside a createQueryBuilder
我的代码:
$qb7Days = $repo->createQueryBuilder('R')
->select( 'R.createdAt' )
->where( "DATE_FORMAT(R.createdAt, '%Y-%m-%d') = :afterDays" )
->andWhere( 'R.cCurrentReviewState = :state' )
->andWhere( 'R.reminder = :reminder' )
->setParameter( 'afterDays', $after7Days )
->setParameter( 'state', $oReviewStateNotVerified ) // not_verified
->setParameter( 'reminder', 0 ) // never sent any reminder
->orderBy( 'R.id', 'ASC' )
->getQuery();
但是我得到了
[DoctrineORMQueryQueryException]
[Syntax Error] line 0, col 7: Error: Expected known function, got 'DATE_FORMAT'
我搜索了一些链接并找到了一些说明它应该以这种方式工作,但对我来说似乎我做错了什么.
I've searched some links and find some explain that it should work this way, but for me it looks like im doing something wrong.
http://www.uvd.co.uk/blog/labs/using-mysqls-date_format-in-doctrine-2-0/
推荐答案
DATE_FORMAT
连同一堆 Mysql 函数在 Doctrine 中不直接可用.
DATE_FORMAT
along with a bunch of Mysql function are not directly available in Doctrine.
要使用它们,您可以创建自己的或添加扩展程序,例如 beberlei/DoctrineExtensions
然后将相应的功能添加到您的学说包配置中,如
To use them you can either create your own or add an extension like beberlei/DoctrineExtensions
and then add the respective function to your doctrine bundle config like
doctrine:
dbal:
....
orm:
....
dql:
string_functions:
DATE_FORMAT: DoctrineExtensionsQueryMysqlDateFormat
相关文章