0

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?

0

You can use

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

But make sure correct sql syntax passed inside where function.

0

You can try using a Zend_Db_Expr object.

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

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.