CakePHP find condition for a query between two dates

前端 未结 6 1179
谎友^
谎友^ 2020-12-30 08:59

I have a start and an end date in my database and a $date variable from a form field. I am now trying to query all the rows where $date is either = start/end date in the db,

6条回答
  •  忘掉有多难
    2020-12-30 10:04

    Here is CakePHP BETWEEN query example.

    I'm defining my arrays as variables, and then using those variables in my CakePHP find function call:

    // just return these two fields
    $fields = array('uri', 'page_views');
    
    // use this "between" range
    $conditions = array('Event.date BETWEEN ? and ?' => array($start_date, $end_date));
    
    // run the "select between" query
    $results = $this->Event->find('all', 
             array('fields'=>$fields, 
                   'conditions'=>$conditions));
    

    Ref from

提交回复
热议问题