Magento – How to add date filter to product collection

collection-filteringcustom-collectiondateproduct-collection

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

Best Answer

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'))));