我想在一天中的某个时间间隔检索数据,
这是我模型中的代码:-
function get_expenditure($where=FALSE){
$this->db->select('*')
->from('expenditure e')
->join('item t','e.registration_number=t.registration_number', 'left');
if ($where) {
$this->db->where($where);
}
$this->db->order_by("e.date_of_expenditure","Asc");
$query = $this->db->get();
return $query->result_array();
}
这是我的控制器
$expenditures=$this->select_model->get_expenditure(array('e.date_of_expenditure'=>$date));
我想你的列date_of_expenditure
具有DATE类型,那么你可以使用BETWEEN
MySQL关键字来查找此间隔内的行。您只需要第一个和最后一个日期:
$expenditures = $this->select_model->get_expenditure('e.date_of_expenditure BETWEEN ' . $dateFrom . ' AND ' . $dateTo);