首页 文章

codeigniter中的GROUP BY日期时间

提问于
浏览
0

如何在codeigniter中使用datetime类型groupby created_at

我的查询

public function get_by_filter($filter){

    if ($filter['type_code'] != "") {
        $this->db->where('type_code',$filter['type_code'],'both');
    }

    // if ($filter['from'] != ""  && $filter['until'] != "") {
    //  $this->db->where('created_at >=', $filter['from']);
    //  $this->db->where('created_at <=', $filter['until']);
    // }
    // if ($filter['from'] != "") {
    //  $this->db->where('created_at >=', $filter['from']);
    // }
    // if ($filter['until'] != "") {
    //  $this->db->where('created_at <=', $filter['until']);
    // }

    $this->db->group_by('created_at');
    $this->db->order_by('id', 'DESC');

    $query = $this->db->get('tbl_payments')->result_array();
    return $query;
}

1 回答

  • 0

    你可以编辑查询;

    试试这个查询

    public function get_by_filter($filter){
    
    
    
        $this->db->select('id, DATE(created_at) AS dateformated');  // 
        $this->db->group_by('dateformated');
        $q = $this->db->get('tbl_payments');
        $results = $q->result_array();
        return $results;
    }
    

相关问题