1

I want the Codeigniter equivalent of the sql below:

select * from `table_name` where DATE_FORMAT('table_name', "%Y-%m") < "YYYY-MM"

I have tried it but get NULL as the answer.Here is how i did it

$this->db->select_sum('column_name')->from('table_name')->where("DATE_FORMAT('column_name','%Y-%m') <","YYYY-MM")->get();

Thnx for any help?

4

3 回答 3

2

使用不带引号column_nameDATE_FORMAT(column_name,'%Y-%m')

$this->db->select_sum('column_name')
         ->from('table_name')
         ->where("DATE_FORMAT(column_name,'%Y-%m') <","YYYY-MM")
         ->get();
于 2013-07-31T10:47:23.173 回答
0

尝试这个

 $this->db->select_sum('column_name')
          ->from('table_name')
          ->where("DATE_FORMAT('column_name','%Y-%m') < YYYY-MM")
          ->get();

您可以在 where 中手动编写自己的子句...阅读文档

于 2013-07-31T10:38:56.123 回答
0

尝试这个

$this->db->select("DATE_FORMAT(your_date_field, 'Year: %Y Month: %m Day: %d') AS formated_date");
$query = $this->db->get('your_table'); 

你只需通过这个线程

于 2013-07-31T10:40:46.200 回答