Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.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 如何在querybuilder中比较两个日期_Php_Symfony_Doctrine Orm_Date Format - Fatal编程技术网

Php 如何在querybuilder中比较两个日期

Php 如何在querybuilder中比较两个日期,php,symfony,doctrine-orm,date-format,Php,Symfony,Doctrine Orm,Date Format,我正在尝试创建一个搜索表单,我需要将所选日期和数据库中的其他日期进行比较。所选日期的格式为(dd/mm/yyyy),保存在数据库中的日期的格式为(mm-dd-yyy) $qb=$this->createQueryBuilder('t')) ->leftJoin('t.image','i')->addSelect('i')) ->leftJoin('t.country','country')->addSelect('country')) ->leftJoin('t.destination','de

我正在尝试创建一个搜索表单,我需要将所选日期和数据库中的其他日期进行比较。所选日期的格式为(dd/mm/yyyy),保存在数据库中的日期的格式为(mm-dd-yyy)

$qb=$this->createQueryBuilder('t'))
->leftJoin('t.image','i')->addSelect('i'))
->leftJoin('t.country','country')->addSelect('country'))
->leftJoin('t.destination','destination')->addSelect('destination'))
->leftJoin('t.airport','airport')->addSelect('airport'))
->其中('t.agence=:agence')
->setParameter('agence',$agence);
//.........
如果(!空($departureDate)){

$qb->andWhere('t.departureDate您的国际化配置错误:您的日期为
mm/dd/yyyy
。您需要更改此行为:

$departureDate = new \DateTime::createFromFormat('dd/mm/YY', $departureDate)
检查这个
$departureDate=new\DateTime::createFromFormat('d/m/Y',$departureDate)->format('m-d-Y');

我通过如下设置查询来解决它:

if (!empty($departureDate)) {
        $date = new \DateTime;
        $qb->andWhere('t.departureDate <= :departureDate')
            ->setParameter('departureDate', $date->createFromFormat('d/m/Y',$departureDate));
    }
if(!empty($departureDate)){
$date=new\DateTime;

$qb->andWhere('t.departureDate我猜
$departureDate=new\DateTime::createFromFormat('d/m/Y',$departureDate)->格式('m-d-Y'))
是您需要的。我得到了这个错误
解析错误:语法错误,意外的T_字符串,需要T_变量或“$”
和phpStorm给我这个错误
对静态类成员的访问不正确
如果(!empty($departureDate)){$qb->and where('t.departureDate我收到了这个错误
解析错误:语法错误,意外的t_字符串,需要t_变量或“$”
和phpStorm给我这个错误
对静态类成员的访问不正确
嘿。请确保你的答案确实有效:)
$departureDate = new \DateTime::createFromFormat('dd/mm/YY', $departureDate)
if (!empty($departureDate)) {
        $date = new \DateTime;
        $qb->andWhere('t.departureDate <= :departureDate')
            ->setParameter('departureDate', $date->createFromFormat('d/m/Y',$departureDate));
    }