DATE_FORMAT在笨活动记录的WHERE条件(DATE_FORMAT in where con

2019-10-29 04:56发布

我想笨相当于下面的SQL:

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

我曾经尝试过,但我做到了让NULL作为answer.Here是

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

日Thnx任何帮助?

Answer 1:

使用不带引号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();


Answer 2:

尝试这个

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

您可以手动编写自己的条款在... 阅读文档



Answer 3:

尝试这个

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

你只是去通过这个THREADS



文章来源: DATE_FORMAT in where condition of Codeigniter Active Record