基本上,我想查询日期范围如下:
$qb = $this->createQueryBuilder("c");
if ($createDateStart) {
$createDateStart = $createDateStart->format('d-M-Y');
$qb->where("c.createDate >= :createDateStart")->setParameter(
"createDateStart", $createDateStart);
}
if ($createDateStart && $createDateEnd) {
$createDateEnd = $createDateEnd->format('d-M-Y');
$qb->andWhere("c.createDate <= :createDateEnd")->setParameter(
"createDateEnd", $createDateEnd);
} else
if ($createDateEnd) {
$createDateEnd = $createDateEnd->format('d-M-Y');
$qb->where("c.createDate <= :createDateEnd")->setParameter(
"createDateEnd", $createDateEnd);
}
这是"创建"的实体:
/**
* @Column(type="datetime")
*/
private $createDate;
但是,当我使用此日期范围进行测试时:$ createAteStart = 01-Jan-2014至$ createAteEnd = 31-Jan-2014。去年的条目即将显示2013年。
我猜我也必须格式化$创建(d-m-y),但是我该如何从查询语句中做到这一点?
我会感谢您的帮助。
$qb->where('e.fecha BETWEEN :monday AND :sunday')
->setParameter('monday', $monday->format('Y-m-d'))
->setParameter('sunday', $sunday->format('Y-m-d'));
在学说2
中选择日期之间的条目它解决了。