仅在cakephp中使用日期条件查询datetime字段

仅在cakephp中使用日期条件查询datetime字段,cakephp,cakephp-2.0,Cakephp,Cakephp 2.0,在cakephp查询条件中,只有日期必须满足表的datetime字段的条件。假设我只有日期(2013-09-21),字段是(2013-09-21 07:45:23)。我很难在这里给出条件。如果@Aryan的解决方案因为需要在数据库中进行格式转换而无法工作,那么您需要使用MySQL函数DATE。这会将查找示例更改为: $date_string = "2013-09-21"; $new_date = date('Y-m-d H:i:s', strtotime($date_string)); $row

在cakephp查询条件中,只有日期必须满足表的datetime字段的条件。假设我只有日期(2013-09-21),字段是(2013-09-21 07:45:23)。我很难在这里给出条件。

如果@Aryan的解决方案因为需要在数据库中进行格式转换而无法工作,那么您需要使用MySQL函数
DATE
。这会将查找示例更改为:

$date_string = "2013-09-21";
$new_date = date('Y-m-d H:i:s', strtotime($date_string));
$row = $this->Model->find('all',
                    array('fields' => array('........'),
                    'conditions' => array(
                        'Story.created >' => $new_date)));
$row = $this->Model->find('all',
                    array('fields' => array('........'),
                    'conditions' => array(
                        'DATE(Story.created) >' => $date)));