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?

3 Answers 3


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.

$whereClause = " status = 'processing' and created_at < (TIMESTAMPADD(MINUTE, -30, CURRENT_TIMESTAMP))";

$collection->getSelect()-> where($whereClause);
  • It could be helpful to explain your answer as the many people reading your answer may have various background. Now, your answer has a syntax error that I can see and this will give you negative feedback. thanks for your answer and your understanding Aug 22, 2020 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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