2

I'm trying to create a collection of all products that have been updated in my store the past 24 hours.

The following code seems to be ok to me. Although I have tried numerous altering versions of it, the collection always ends up with 0 products.

$now = date('Y-m-d H:i:s', time());
$last_allowed_update = date('Y-m-d H:i:s', strtotime($now.'- 24 hours') );

$productCollection = Mage::getResourceModel('catalog/product_collection');
$productCollection->addAttributeToSelect('*');
$productCollection->addAttributeToFilter('updated_at', array('from'=>$last_allowed_update));
2

it is better to use Magento framework to get the date

you should use

Mage::getModel('core/date')->gmtDate('Y-m-d H:i:s');

try this code

$now = Mage::getModel('core/date')->gmtDate('Y-m-d H:i:s');
$last_allowed_update = date('Y-m-d H:i:s', strtotime($now.'- 24 hours') );

$productCollection = Mage::getResourceModel('catalog/product_collection');
$productCollection->addAttributeToSelect('*');
$productCollection->addAttributeToFilter('updated_at', array('from'=>$last_allowed_update));
  • Thank for this suggestion. But I still get zero products. – zekia Apr 28 '18 at 5:25
  • Do you have updateed products in the last 24 hours? Just try to open any product and click save – WISAM HAKIM Apr 28 '18 at 11:41
  • Yes, of course there are updated products. Filtering products in magento administration by Date Updated, gives me about 300 products updated the pas 24 hours – zekia Apr 28 '18 at 12:17

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.