1

我需要在 cakephp 中以一年的间隔获取记录。我尝试使用以下按time条件查询不起作用。

$accept = $this->AssignListing->find('all',array('conditions' => array('AssignListing.writer_id' => $writer,'AssignListing.status' => 1, 'AssignListing.date_added > NOW( ) - INTERVAL 1 YEAR')));

4

3 回答 3

1

在这种情况下不是更容易:

$str_time = date('Y-m-d H:i:s', strtotime('-1 Year'));

$accept = $this->AssignListing->find('all',array('conditions' => array(
'AssignListing.writer_id' => $writer,
'AssignListing.status' => 1, 
'AssignListing.date_added >' => $str_time)));

并比较该值?如果可能,请在 php 中进行一次计算并解析它而不是在 MySQL 中。

strtotime()
日期()

于 2012-08-06T08:45:52.620 回答
1

我认为这会解决问题,

$accept = $this->AssignListing->find('all',array('conditions' => array(
'AssignListing.writer_id' => $writer,
'AssignListing.status' => 1, 
array('AssignListing.date_added BETWEEN ? AND ?' => array(date('Y-m-d', strtotime("-1 Year")), date('Y-m-d'))))));
于 2012-08-06T08:59:09.463 回答
1

这对你有用。

$accept = $this->AssignListing->find('all',array('conditions' => array('AssignListing.writer_id' => $writer,'AssignListing.status' => 1, 'AssignListing.date_added >=' => 'DATE_ADD(NOW( ), INTERVAL -1 YEAR')));
于 2012-08-06T09:01:44.967 回答