使用'DATE_SUB(now(),INTERVAL 2 MONTH)'正确使用Codeigniter

I'm trying to run this query with Codeigniter:

SELECT * FROM `bf_bs_history` WHERE date > DATE_SUB(now(), INTERVAL 2 MONTH) 

If I enter it directly in phpMyAdmin, I get the result I want. However, running if from the code, it will not take any effect. It's not filtering at all. The PHP line looks like this:

$this->history_model->where(array('date > ' => 'DATE_SUB(now(), INTERVAL 2 MONTH)'))->find_all();

Any idea where I go wrong?

CodeIgniter Active Record is adding backticks to your statement, which renders your clause as a string, not an executable function. You can set a second parameter to false to stop that. Also, for a function predicate like this you can simply pass in the string:

$this->history_model->where("date > DATE_SUB(now(), INTERVAL 2 MONTH)", false)->find_all();