Symfony2 - 如何修复下个月的第一天被包括在上个月


Symfony2 - How to fix the first day of the next month being included as the previous month?

我的学说查询目前正在查询一个月内的所有帖子,以获取侧边栏中的帖子存档。

问题是当我点击 2013 年 10 月(这应该只显示 10 月的帖子)但是,11 月 1 日,下个月的 1 日也被包括在内。

我该如何解决此问题,以便当月的第一天不作为上个月的帖子包含在内?

教义2

查询
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();
}

更改

$toDate->修改("下个月的第一天午夜");

$toDate->修改("下个月午夜-1秒");