I was wondering if there is any way to add a date filter to a product collection. What i am trying to do: I have a collection for new products, i need to add a filter to it so it filter the products by date. i dont need all days just three past days. The idea is just like layered navigation just the option must be three past days and they mus be generated dynamically. Note: The date mus be selected in frontend by the user. THanks in advance

1 Answer 1


I'm not sure about your actual use case, but to filter a product collection so that it only returns products created within the last 3 days do as follows

$collection = Mage::getResourceModel('catalog/product_collection')
    ->addFieldToFilter('created_at', array('gt' => date("Y-m-d H:i:s", strtotime('-3 day'))));
  • No i want to select the date in frontend.
    – Ylli
    Commented Dec 12, 2014 at 15:09
  • Well that's entirely dependent on your frontend implementation. Perhaps an ajax request to a controller, gets given the date, converts it using strtotime (as above) to show past X days, then loads and returns the product data you need. Commented Dec 12, 2014 at 16:22
  • Well thank you for the answer but i need a little bit help implementing it. Its beyond my magento knowledge. I can make the controller but i dont know how to create the frontend part and send data with ajax request.
    – Ylli
    Commented Dec 13, 2014 at 8:51

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.