0

Hello Please help me to updated this query to apply updated_at filter too with OR condition.

Here If I want to add 'updated_at' too in the filter with the same condition like 'created_at' then what should I do in below query:

 $products = Mage::getResourceModel('catalog/product_collection')
                                    ->addAttributeToSelect('*')
                                    ->addFieldToFilter('created_at', array(
                                    'from'     => strtotime('-2 days', time()),
                                    'to'       => time(),
                                    'datetime' => true
                                ))->load();

Please help

1 Answer 1

0

Try This :-

$fromDate = date('Y-m-d H:i:s', strtotime('-2 days', time());
$toDate = date('Y-m-d H:i:s', strtotime(now()));
$products = Mage::getResourceModel('catalog/product_collection')
                                    ->addAttributeToSelect('*')
                                    ->addFieldToFilter('created_at', array(
                                    'from'     => $fromDate,
                                    'to'       => $toDate,
                                    'datetime' => true,
                                ))->load();
3
  • but I also want updated_at in filter with OR condition.
    – Stack user
    May 31, 2019 at 10:06
  • please explain briefly which you want ?? May 31, 2019 at 10:08
  • I want to get all products which are either created or updated from last two days.
    – Stack user
    May 31, 2019 at 10:17

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.