我正在尝试创建查询以查找2014年内的所有帖子。
我有以下内容但出现错误:
[Syntax Error] line 0, col 88: Error: Expected end of string, got '00'
我的查询有什么问题?
public function getPostCountByYear()
{
$query = $this
->createQueryBuilder('post')
->where('created >= 2014-01-01 00:00:00 AND created < 2015-01-01 00:00:00');
$query->select('COUNT(post)');
$year = $query
->getQuery()
->getSingleScalarResult();
return $year;
}
答案 0 :(得分:0)
试试这个。
public function getPostCountByYear()
{
$query = $this
->createQueryBuilder('post')
->where('post.created >= :begin')
->andWhere('post.created < :end')
->setParameter('begin', new \DateTime('2014-01-01 00:00:00'))
->setParameter('end', new \DateTime('2015-01-01 00:00:00'));
$query->select('COUNT(post.created)');
$year = $query
->getQuery()
->getSingleScalarResult();
return $year;
}