2015-04-17 34 views
0

我在codeigniter中工作,我的问题是我想选择月份&年在下面的查询..它返回月份,但我需要一个月作为一个月&年值..请帮助..如何在codeigniter活动记录中选择MONTH()和YEAR()

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

你尝试YEAR(newsroom_publish_date)? –

回答

2

试试这个:

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

MONTH功能MySQL,用YEAR功能相同。

这样做:

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从给定时间戳的回报。

让我知道更多的帮助!

+0

我告诉他的评论;) –

+0

对不起,我忘记提及,我需要一个月和一年的价值.. – SureshK

+1

然后concat两个值 –

相关问题