doue9730 2016-05-03 05:17 采纳率: 100%
浏览 30
已采纳

如何比较php codeigniter中的日期和年份

My model

public function get_payscale() {
    $this->db->from('payscale P')->join('employee E','E.employee_id = P.employee_id ');
    $this->db->where('P.payscale_date',date('Y-m'));
    return $this->db->get()->result_array();
}   

I want to compare only month and year with the db which in the format y-m-d, where i want only to retrieve the y-m using where clause. any help would be appreciated

  • 写回答

3条回答 默认 最新

  • dslk6326846 2016-05-03 05:19
    关注

    Use like this :

    $this->db->where('EXTRACT(YEAR_MONTH FROM P.payscale_date)',date('Ym'));
    

    This query will extract the Year and month from the date given column like 201605 (2016-05-21)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?