Symfony 使用条令选择从月初到当前日期的记录

Symfony 使用条令选择从月初到当前日期的记录,symfony,doctrine,doctrine-orm,Symfony,Doctrine,Doctrine Orm,我在从条令中获取数据时遇到两个问题: 选择从月初到当前日期的记录 选择从年初到当前日期的记录 我怎样才能写一个和我们做同样的事情 这是我的存储库中不完整的代码 public function findByYearlyAttendanceTillToday($id) { $em = $this->getEntityManager(); $query = $em->createQuery("SELECT count(a) FROM CollegeStudentBundle

我在从条令中获取数据时遇到两个问题:

  • 选择从月初到当前日期的记录
  • 选择从年初到当前日期的记录
  • 我怎样才能写一个和我们做同样的事情

    这是我的存储库中不完整的代码

    public function findByYearlyAttendanceTillToday($id)
    {
        $em = $this->getEntityManager();
        $query = $em->createQuery("SELECT count(a) FROM CollegeStudentBundle:StudentAttendance a where a.present LIKE 'A' and a.student_id = :id and a.date > :date");
        $query->setParameter('id', $id);
        $query->setParameter('date', **?????**);
        return $query->getResult();
    }
    
    以下是您需要的:

    new \DateTime('midnight first day of this month');
    new \DateTime('first day of january');
    
    我还要改变这一点:

    a.date > :date
    
    为此:

    a.date >= :date
    

    伟大的它起作用了。。你能让我知道任何我可以通过new\DateTime(“”)阅读所有其他参数的引用吗;非常感谢,先生,但是我在任何地方都找不到“本月第一天午夜”的争论。谢谢你的回答。我还有一个问题。您能看一下吗
    new\DateTime(“今天的第一天”)
    new\DateTime(“本月的第一天午夜”)的一个简短替代方案。