如何比较php codeigniter中的日期和年份 [英] how to compare only date and year in php codeigniter

查看:127
本文介绍了如何比较php codeigniter中的日期和年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模型

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();
}   

我想只比较月份和年份,其中格式为ymd ,其中我只想使用where子句检索ym。

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

推荐答案

使用这样:

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

此查询将从提供的日期提取年份和月份,如2016/05 )

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

这篇关于如何比较php codeigniter中的日期和年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆