[英]How to select MONTH() and YEAR() in codeigniter active record
I am working in codeigniter, my problem is i want to select month & year in below query.. it returns month but i need month & year as a single value.. please help.. 我在codeigniter中工作,我的问题是我想在下面的查询中选择月和年。它返回月,但我需要将月和年作为单个值..请帮助..
public function get_content(){
$this->db->select('MONTH(newsroom_publish_date) as month');
$this->db->from('content_table');
$this->db->where('status', "Active");
$query = $this->db->get();
return $query->result();
}
Same as MONTH
function in MySQL
, use YEAR
function for the same. 与
MySQL
MONTH
函数相同,使用YEAR
函数相同。
Do like this: 这样做:
public function get_content(){
$this->db->select('MONTH(newsroom_publish_date) as month, YEAR(newsroom_publish_date) as year');
$this->db->from('content_table');
$this->db->where('status', "Active");
$query = $this->db->get();
return $query->result();
}
YEAR returns from given timestamp. YEAR从给定的时间戳返回。
Let me know for more help! 让我知道更多帮助!
Try this: 尝试这个:
public function get_content(){
$this->db->select('CONCAT(MONTH(newsroom_publish_date)),'-',(YEAR(newsroom_publish_date)) as year_month);
$this->db->from('content_table');
$this->db->where('status', "Active");
$query = $this->db->get();
return $query->result();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.