从Doctrine日期范围获取总小时数

时间:2016-01-25 08:09:32

标签: symfony doctrine-orm

我想根据教义'BETWEEN'得到所有字段(时间)的总小时数。这正是存储库中的代码

  public function findTotalHoursByDateStartDateEnd($from,$to,$user)
{
    return $this
        ->createQueryBuilder('t')
        ->select('t.timein','t.timeout')
        ->where('t.workingday BETWEEN :from AND :to')
        ->andWhere('t.users = :id')
        ->setParameter('from', $from)
        ->setParameter('to', $to)
        ->setParameter('id', $user)
        ->orderBy('t.workingday', 'ASC')
        ->getQuery()
        ->getResult()
    ;
}

控制器

  $em = $this->getDoctrine()->getManager();
    $entity = new Payroll();
    $user = $request->request->get('edgeweb_project_payrollbundle_payroll')['user'];
    $from = $request->request->get('edgeweb_project_payrollbundle_payroll')['start'];
    $to = $request->request->get('edgeweb_project_payrollbundle_payroll')['end'];

    $total_hours = $em->getRepository('EmployeeBundle:Timerecord')->findTotalHoursByDateStartDateEnd($from,$to,$user);

使用这个var_dump函数,我知道上面的方法返回了预期的值

array(1) { [0]=> array(2) { ["timein"]=> object(DateTime)#456 (3) { ["date"]=> string(26) "1970-01-01 14:12:20.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(11) "Asia/Manila" } ["timeout"]=> object(DateTime)#446 (3) { ["date"]=> string(26) "1970-01-01 14:12:27.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(11) "Asia/Manila" } } }

但是我很困惑如何只返回上面查询的总小时数。

实体

   //DateTime
   private timein;

    //DateTime
   private timeout;

更新

  user 1
      **from**(january1)            **to** (january4)
         t/i    t/o                   t/i    t/o
      jan 1 4:00  5:00(1 hrs)        jan 3 4:50: 5:50(1 hrs)
      jan 2 3:50  4:50 (1 hrs)        jan 4 5:00  5:30(30 min)

      total = 3.30(3 hrs 30 minutes)///this is the result I want

任何想法?

0 个答案:

没有答案