codeigniter:获取在两个date之间发布的数据
如何使用codeigniter的activerecord查询两个date之间的logging,从数据库中检索数据?
谢谢
这看起来像你所需要的:
$this->db->where('order_date >=', $first_date); $this->db->where('order_date <=', $second_date); return $this->db->get('orders');
尝试这个:
$this->db->where('sell_date BETWEEN "'. date('Ym-d', strtotime($start_date)). '" and "'. date('Ym-d', strtotime($end_date)).'"');
希望这会工作
这对我很好
$this->db->where('sell_date BETWEEN "'. date('Ym-d', strtotime($start_date)). '" and "'. date('Ym-d', strtotime($end_date)).'"');
愿这对您有所帮助….join三张桌子
public function get_details_beetween_dates() { $from = $this->input->post('fromdate'); $to = $this->input->post('todate'); $this->db->select('users.first_name, users.last_name, users.email, groups.name as designation, dailyinfo.amount as Total_Fine, dailyinfo.date as Date_of_Fine, dailyinfo.desc as Description') ->from('users') ->where('dailyinfo.date >= ',$from) ->where('dailyinfo.date <= ',$to) ->join('users_groups','users.id = users_groups.user_id') ->join('dailyinfo','users.id = dailyinfo.userid') ->join('groups','groups.id = users_groups.group_id'); /* $this->db->select('date, amount, desc') ->from('dailyinfo') ->where('dailyinfo.date >= ',$from) ->where('dailyinfo.date <= ',$to); */ $q = $this->db->get(); $array['userDetails'] = $q->result(); return $array; }
$query = $this->db ->get_where('orders',array('order_date <='=>$first_date,'order_date >='=>$second_date)) ->result_array();
如果你想比较SQLdate,你可以试试这个:
$this->db->select(); $this->db->from('table_name'); $this->db->where(' date_columnname >= date("'.$from.'")'); $this->db->where( 'date_columnname <= date("'.$to.'")');
这对我有用(PHP和MySQL)。
如果你想在Codeigniter查询帮助器上强制使用BETWEEN关键字。 你可以使用这个代码没有逃生错误的地方。 在CI版本3.1.5上运行良好。 希望它帮助别人。
if(!empty($tglmin) && !empty($tglmax)){ $this->db->group_start(); $this->db->where('DATE(create_date) BETWEEN "'.$tglmin.'" AND "'.$tglmax.'"', '',false); $this->db->group_end(); }