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?

4

You can try using a Zend_Db_Expr object.

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

You can use

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

But make sure correct sql syntax passed inside where function.

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

$collection->getSelect()-> where($whereClause);
| improve this answer | |
  • 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 – Herve Tribouilloy Aug 22 at 9:33

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.