Pergunta

I was wondering how to display records that have date which suits to current week. For example if we have days from 12.05 to 18.05 and we have record in table with rows From with value 12.05 and To with value 18.05.

I was trying to do this, but it doesn't works as I wanted. The problem is that record is displayed but only if the From value is exactly the same as current date. Here's my code:

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)
    ))
    );
}

And my question is, how to do that?

Foi útil?

Solução

Try this:

$week_start = date('Y-m-d', strtotime("-1 weeks"));
$week_end = date('Y-m-d');

$conditions = array(
    "From >" => $week_start,
    "From <=" => $week_end,
);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top