Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何向条令查询添加日期?_Php_Doctrine Orm_Doctrine - Fatal编程技术网

Php 如何向条令查询添加日期?

Php 如何向条令查询添加日期?,php,doctrine-orm,doctrine,Php,Doctrine Orm,Doctrine,我有一个Y-m-d H:I:s格式的日期字段。现在用户只能使用日期进行搜索。我有这样的疑问: $qb->andWhere('DATE(vc.updatedDatetime) >= :startDate AND DATE(vc.updatedDatetime) <= :endDate') ->setParameter('startDate', $filterArray['startDate']) ->setParameter('endDate', $filterArr

我有一个
Y-m-d H:I:s
格式的日期字段。现在用户只能使用日期进行搜索。我有这样的疑问:

$qb->andWhere('DATE(vc.updatedDatetime) >= :startDate AND DATE(vc.updatedDatetime) <= :endDate')
->setParameter('startDate', $filterArray['startDate'])
->setParameter('endDate', $filterArray['endDate']);
但我得到了以下错误:

Attempted to load class "Date" from namespace "DoctrineExtensions\Query\Mysql".
Did you forget a "use" statement for e.g. "Twig_Extensions_Extension_Date" or "Symfony\Component\Validator\Constraints\Date"?
虽然您可以创建自己的扩展来将
DATE
函数添加到条令中,或者下载类似的东西来为您执行,但最终这是浪费时间。你不需要它

你可以简单地做:

$qb
    ->andWhere('vc.updatedDatetime > :startDate')
    ->andWhere('vc.updatedDatetime < :endDate')
    ->setParameter('startDate', $startDate)
    ->setParameter('endDate', $endDate)

假设提供的日期是“YYYY-MM-DD”格式,这似乎是因为您使用代码的方式,以上内容就足够了。

我发现了这个问题<代码>编写器需要beberlei/DoctrineExtensions
$qb
    ->andWhere('vc.updatedDatetime > :startDate')
    ->andWhere('vc.updatedDatetime < :endDate')
    ->setParameter('startDate', $startDate)
    ->setParameter('endDate', $endDate)
$endDate = (new DateTime($filterArray['endDate']))->add(new DateInterval('P1D'))