1

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

4

You can try using a Zend_Db_Expr object.

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

You can use

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

But make sure correct sql syntax passed inside where function.

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

$collection->getSelect()-> where($whereClause);
1
  • 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 Commented 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.