Sunday, November 10, 2013

Get Todays start and end date with time in Magento

Some time we need to get collection of report or product collection of today date ,at that time need to set start date from 00:00:00 time and end with 23:59:59 for that use below code
 $todayStartOfDayDate      = Mage::app()->getLocale()->date()->setTime('00:00:00')->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
    $todayEndOfDayDate      = Mage::app()->getLocale()->date()->setTime('23:59:59')->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); 
or eg:- newarrival of product collection;
 $proCollection = Mage::getModel('catalog/product')
                        ->getCollection()
                        ->addAttributeToSelect(array('entity_id'))
                        ->addAttributeToFilter('news_from_date', array('or'=> array(
                                    0 => array('date' => true, 'to' => $todayEndOfDayDate),
                                    1 => array('is' => new Zend_Db_Expr('null')))
                                ), 'left')
                                ->addAttributeToFilter('news_to_date', array('or'=> array(
                                    0 => array('date' => true, 'from' => $todayStartOfDayDate),
                                    1 => array('is' => new Zend_Db_Expr('null')))
                                ), 'left')
                                ->addAttributeToFilter(
                                    array(
                                        array('attribute' => 'news_from_date', 'is'=>new Zend_Db_Expr('not null')),
                                        array('attribute' => 'news_to_date', 'is'=>new Zend_Db_Expr('not null'))
                                        )
                                 ); 
http://www.magentocommerce.com/boards/viewthread/704170/

No comments:

Post a Comment