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?
Use without quotes column_name
like DATE_FORMAT(column_name,'%Y-%m')
$this->db->select_sum('column_name')
->from('table_name')
->where("DATE_FORMAT(column_name,'%Y-%m') <","YYYY-MM")
->get();
try this
$this->db->select_sum('column_name')
->from('table_name')
->where("DATE_FORMAT('column_name','%Y-%m') < YYYY-MM")
->get();
You can write your own clauses manually in where... read the docs
try this
$this->db->select("DATE_FORMAT(your_date_field, 'Year: %Y Month: %m Day: %d') AS formated_date");
$query = $this->db->get('your_table');
you just go through this THREADS