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