Here's a method I've used for something quite similar (in this case, using the "Special Price" date range for the product).
I've extended from Mage_Catalog_Block_Product_List
protected function _saleList()
{
parent::_construct();
$this->setTemplate('saleitems.phtml');
// This should get the time localized to your timezone setting
$timestamp = Mage::getModel('core/date')->timestamp(time());
$this->_today = date('m/d/y h:i:s', $timestamp);
// I've set these as class properties, but you could just use a plain old variable if you like. I don't use these here but use them for listing upcoming and expired items.
$this->_tomorrow = date('m/d/y', mktime(0, 0, 0, date('m'), date('d') + 1, date('y')));
$this->_oneWeek = date('m/d/y', mktime(0, 0, 0, date('m'), date('d') + 7, date('y')));
$this->_yesterday = date('m/d/y', mktime(0, 0, 0, date('m'), date('d') - 1, date('y')));
// Here's the important bit. Note the `from` and `to` arguments passed in the array when filtering the dates. `to` is essentially a <=, and `from` is >= and they are used for dates.
$collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED))
->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $this->_today))
->addAttributeToFilter('special_to_date', array('date' => true, 'from' => $this->_today))
->addAttributeToSort('special_to_date', 'asc');
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
// In your template, you can call $this->getSaleItems() and then iterate over each
$this->setSaleItems($collection);
}
you are using wrong date format in argument of function
use below format to get your desired out put
echo Mage::getModel('core/date')->date('M d, Y h:m:s', strtotime('2013-02-19 17:26:37'));
OUTPUT
Feb 19, 2013 18:02:37
Hope this will sure work for you.
Best Answer
I suggest,
Create new two date attribute product attribute.W
available_from_date
->the start date from where the productwill be show on product listing
will be stop on product listing
This two attribute manage the product wise available time .Just like h product new from date and product new to date.
Now you need to set product those two field value from admin
Then using below events filter the product collection by :
catalog_block_product_list_collection
(used by review module, after collection is loaded its not editable anymore)catalog_product_collection_load_before
catalog_product_collection_load_after
See catalog_product_collection_load_before and getLoadedProductCollection
Then make event area
fronted
thus eventwill fire on frontend area
Example using event:
On event filter the collection by below code:
Observer look like: