Doctrine orm 如何从学说中的日期时间寄存器中获取日期?

Doctrine orm 如何从学说中的日期时间寄存器中获取日期?,doctrine-orm,doctrine,dql,doctrine-query,Doctrine Orm,Doctrine,Dql,Doctrine Query,我使用codeigniter和条令,这是我的bd: id fecha_publicacion 1 2013-03-23 14:52:06 2 2013-03-23 18:02:06 3 2013-03-23 00:00:00 .. ... 我想做的是搜索某个日期或某个日期范围内的出版物 问题是,如果我想选择日期为2013-03-23的所有字段,我的查询只返回3erd字段(时间为00:00:00) 我怎样才能得到我想要的?我尝试过很多事情,但都没有成功 public function

我使用codeigniter和条令,这是我的bd:

id fecha_publicacion
1  2013-03-23 14:52:06
2  2013-03-23 18:02:06
3  2013-03-23 00:00:00
..   ...
我想做的是搜索某个日期或某个日期范围内的出版物

问题是,如果我想选择日期为2013-03-23的所有字段,我的查询只返回3erd字段(时间为00:00:00)

我怎样才能得到我想要的?我尝试过很多事情,但都没有成功

public function postsByDates($tipo,$fecha1,$fecha2=''){
    if($fecha2 == ''){
        $fecha2 = $fecha1;
    }

    $this->qb = $this->em->createQueryBuilder();
    $this->qb->select('p')
    ->from('models\Post', 'p')
    ->where(
        $this->qb->expr()->eq('p.tipo', '?1'),
        $this->qb->expr()->between('p.fecha_publicacion', '?2', '?3')
            )   
    ->setParameter(1, $tipo)
    ->setParameter(2, "$fecha1%")
    ->setParameter(3, "$fecha2%");

    $query = $this->qb->getQuery();
    $obj = $query->getResult();

    return $obj;
}

问题是您正在为datetime/时间戳比较提供一个日期。所以我猜它会将您提供的日期(2013-03-23)转换为时间戳(2013-3-23 00:00:00)

快速修复:您可以有两个日期,如“2013-03-23 00:00:00”和“2013-03-23 23:59:59”

好的解决方案:您可以使用DQL原生查询调用MySQL函数将时间戳字段(fecha_publicacion)转换为日期。之后,您将能够使用between函数