How can I use something like this one NOW() - INTERVAL 10 DAY in collection filter?

->addFieldToFilter('period', ['gteq' => 'NOW() - INTERVAL 1 DAY'])

Before running the query, the value in the filter is going to be converted into a string, so MySQL will not run it as functions.

Is there any way I can use the MySql functions in a filter?


You can try using a Zend_Db_Expr object.

->addFieldToFilter('period', ['gteq' => new \Zend_Db_Expr('NOW() - INTERVAL 1 DAY')])

You can use

$collection->getSelect()->where("period >= NOW() - INTERVAL 1 DAY");

But make sure correct sql syntax passed inside where function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.