【发布时间】:2014-05-14 13:38:07
【问题描述】:
我的学说查询目前正在查询一个月内的所有帖子,以获取侧栏中的帖子存档。
问题是当我点击 2013 年 10 月时(这应该只显示 10 月的帖子)但是,11 月 1 日,下个月的 1 日也包括在内。
我怎样才能解决这个问题,使当月的第一天不包含在上个月的帖子中?
Doctrine2 查询
public function getPostsByMonth($year, $month)
{
// Query for blog posts in each month
$date = new \DateTime("{$year}-{$month}-01");
$toDate = clone $date;
$toDate->modify("first day next month midnight");
$qb = $this->createQueryBuilder('b')
->where('b.created BETWEEN :start AND :end')
->setParameter('start', $date)
->setParameter('end', $toDate)
;
return $qb->getQuery()->getResult();
}
【问题讨论】:
标签: php symfony doctrine-orm archive