我需要在cakephp中获取一年间隔内的记录。我试过time
以下的查询条件不起作用。
$accept = $this->AssignListing->find('all',array('conditions' => array('AssignListing.writer_id' => $writer,'AssignListing.status' => 1, 'AssignListing.date_added > NOW( ) - INTERVAL 1 YEAR')));
答案 0 :(得分: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中。
答案 1 :(得分: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'))))));
答案 2 :(得分: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')));