我想知道如何显示具有适合当前周的日期的记录。例如,如果我们有从12.05到18.05的天数,并且我们在表中记录了行值为12.05的To和值为18.05的To。
我试图这样做,但它并没有按照我的意愿行事。问题是显示记录,但仅当From值与当前日期完全相同时才显示。这是我的代码:
public function index() {
$date = date('o-m-d');
$oneWeekLater = strtotime('+1 Week');
$twoWeekLater = strtotime('+2 Week');
$date_next = date('o-m-d', $oneWeekLater);
$date_next_two = date('o-m-d', $twoWeekLater);
$this->set('timetables', $this->Timetable->find('all', array(
'conditions' => array('From' => $date_next)
))
);
$this->set('timetables_plus', $this->Timetable->find('all', array(
'conditions' => array('From' => $date_next)
))
);
$this->set('timetables_plus_two', $this->Timetable->find('all', array(
'conditions' => array('From' => $date_next_two)
))
);
}
我的问题是,怎么做?
答案 0 :(得分:4)
试试这个:
$week_start = date('Y-m-d', strtotime("-1 weeks"));
$week_end = date('Y-m-d');
$conditions = array(
"From >" => $week_start,
"From <=" => $week_end,
);