Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.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/8/mysql/64.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 比较mysql/symfony2中的日期_Php_Mysql_Symfony - Fatal编程技术网

Php 比较mysql/symfony2中的日期

Php 比较mysql/symfony2中的日期,php,mysql,symfony,Php,Mysql,Symfony,我一直在寻找这个,还有一些相关的问题,但是没有人给我我需要的答案。我有一个带有日期字段的实体,我需要选择从现在起超过7天的人: $query = $repository->createQueryBuilder('rf') ->where('rf.sendDate >='.new \DateTime('-7 days')) ->getQuery(); 我发现这个错误: Catchable Fa

我一直在寻找这个,还有一些相关的问题,但是没有人给我我需要的答案。我有一个带有日期字段的实体,我需要选择从现在起超过7天的人:

$query = $repository->createQueryBuilder('rf')
                    ->where('rf.sendDate >='.new \DateTime('-7 days'))
                    ->getQuery();
我发现这个错误:

Catchable Fatal Error: Object of class DateTime could not be converted to string
我想知道的是,当在实体中定义为DateTime对象时,为什么它会假定
rf.sendDate
是一个字符串?我怎么能比较这个呢


谢谢你的解释

您应该为此使用参数:

    $query = $repository->createQueryBuilder('rf')
            ->where('rf.sendDate >= :ts')
                ->setParameter('ts', new \DateTime('-7 days'))
            ->getQuery();

您应该为此使用参数:

    $query = $repository->createQueryBuilder('rf')
            ->where('rf.sendDate >= :ts')
                ->setParameter('ts', new \DateTime('-7 days'))
            ->getQuery();