从数据库获取月份日期

时间:2016-03-23 05:01:37

标签: php codeigniter codeigniter-3

如何从数据库中获取发布数据结果的月份和年份?

我想从数据库中检索的数据是2016-03-11

我在控制器内的代码:

public function report(){
    $nomor = $this->input->post('nomor_reseller');
    $bulan = $this->input->post('month'); //with format YYYY-MM

    $report_data = $this->hasil_m->get($nomor,$bulan);
    }

我在模型中的代码:

function get($nomor,$bulan) {
    $this->db->where('nomor_reseller',);
    $this->db->where('tgl_pembelian',);     
    $this->db->select('*');
    $this->db->from('tb_pelanggan');
    $this->db->join('tb_anggota', 'tb_anggota.id_koperasi = tb_pelanggan.id_koperasi');
    $this->db->order_by("tgl_pembelian","DESC");
    $this->db->group_by('nomor_reseller');      
    $query = $this->db->get ();
    if ($query->num_rows() > 0) {
        return $query->result();
    } else {
        return false;
    }
}

我想要做的是获取2016-03,使用$ this-> db-> where。

1 个答案:

答案 0 :(得分:0)

您可以尝试:

echo date('Y-m', strtotime($date));
相关问题