Symfony 2 PHP比较日期问题
使用PHP5.5.9。我有一个Tranche实体,它有一个日期属性。我想要的是得到符合条件的行数;日期gt/lt为当前日期,因此我创建了一个细枝扩展,这是我的代码: 此后 我的问题是,无论我怎么做,我都无法比较日期 这就是错误: DateType.php第53行:错误:对非对象调用成员函数format()Symfony 2 PHP比较日期问题,php,symfony,date,Php,Symfony,Date,使用PHP5.5.9。我有一个Tranche实体,它有一个日期属性。我想要的是得到符合条件的行数;日期gt/lt为当前日期,因此我创建了一个细枝扩展,这是我的代码: 此后 我的问题是,无论我怎么做,我都无法比较日期 这就是错误: DateType.php第53行:错误:对非对象调用成员函数format() 我搜索了很多,尝试了很多建议,但都没用,我被卡住了。发生了什么事并提前向您表示感谢。如@Qoop所说解决了。应该是: public function e() { $criteria = ne
我搜索了很多,尝试了很多建议,但都没用,我被卡住了。发生了什么事并提前向您表示感谢。如@Qoop所说解决了。应该是:
public function e() {
$criteria = new \Doctrine\Common\Collections\Criteria();
$d=date('Y-m-d'); // i think your error is here
$timestamp = strtotime($d); //here
$date=date('Y-m-d',$timestamp); //and here
$d = //place here where the date is coming from
$date = date('Y-m-d', strtotime($d)); //formatter of date
$criteria->where($criteria->expr()->lt('date',$date));
$result=$this->em->getRepository('OCUserBundle:Tranche')->matching($criteria);
return count($result);
}
$criteria->where($criteria->expr()->lt('date', new \DateTime()));
正如@Qoop所说的那样解决。应该是:
$criteria->where($criteria->expr()->lt('date', new \DateTime()));
正如@Qoop所说的那样解决。应该是:
$criteria->where($criteria->expr()->lt('date', new \DateTime()));
正如@Qoop所说的那样解决。应该是:
$criteria->where($criteria->expr()->lt('date', new \DateTime()));
即使您尝试$date=date('Y-m-d',strottime($timestamp))?;按照你的建议做了,同样的错误。我甚至不知道错误是从哪里来的。你从哪里得到你的约会?您正在转换它两次。
$criteria->where($criteria->expr()->lt('date',new\DateTime())代码>即使您尝试$date=date('Y-m-d',strottime($timestamp))?;按照你的建议做了,同样的错误。我甚至不知道错误是从哪里来的。你从哪里得到你的约会?您正在转换它两次。$criteria->where($criteria->expr()->lt('date',new\DateTime())代码>即使您尝试$date=date('Y-m-d',strottime($timestamp))?;按照你的建议做了,同样的错误。我甚至不知道错误是从哪里来的。你从哪里得到你的约会?您正在转换它两次。$criteria->where($criteria->expr()->lt('date',new\DateTime())代码>即使您尝试$date=date('Y-m-d',strottime($timestamp))?;按照你的建议做了,同样的错误。我甚至不知道错误是从哪里来的。你从哪里得到你的约会?您正在转换它两次。$criteria->where($criteria->expr()->lt('date',new\DateTime())代码>感谢您的努力。Qoop回答了我的问题。没问题@AbdelazizDabebi。我意识到你想要得到现在的时间。谢谢你的努力。Qoop回答了我的问题。没问题@AbdelazizDabebi。我意识到你想要得到现在的时间。谢谢你的努力。Qoop回答了我的问题。没问题@AbdelazizDabebi。我意识到你想要得到现在的时间。谢谢你的努力。Qoop回答了我的问题。没问题@AbdelazizDabebi。我意识到你想知道现在的时间。