I need to get order details from range of dates(from date and To date) For that i am using below code but i am not getting

enter image description here

while printing order collection, i am getting a long array.... i need to get order detail like email id,product details. thanks in advance

4 Answers 4


i think only problem with you variable add time with them..

$fromDate='2016-3-5 00:00:00';
$tomDate='2016-3-10 00:00:00';
  • after changing the format,not getting any result
    – Abdul Aziz
    Commented Mar 10, 2016 at 8:13
  • updated the code add these line too and make sure you have correct path of Mage.php Commented Mar 10, 2016 at 8:34
  • while printing (print_r($or)) , nothing print....blank only.If we are printing(print_r($orderCollection)), a long array printing. starting with Mage_Sales_Model_Resource_Order_Collection Object ( [_eventPrefix:protected] => sales_order_collection [_eventObject:protected] => order_collection [_model:protected] => sales/order [_resourceModel:protected] => sales/order [_resource:protected] => Mage_Sales_Model_Resource_Order Object (
    – Abdul Aziz
    Commented Mar 10, 2016 at 9:15
  • echo $or; and print_r($orderCollection->getData()); will show you result. Commented Mar 10, 2016 at 9:20
  • giving result : Array ( )
    – Abdul Aziz
    Commented Mar 10, 2016 at 9:50

Your code as below

    $from_date = date("Y-m-d h:m:s", strtotime(2016-3-5));
    $to_date = date("Y-m-d h:m:s", strtotime(2016-3-10));

    $orderCollection = Mage::getModel('sales/order')->getCollection()
        ->addAttributeToFilter('created_at', array('from'=>$from_date, 'to'=>$to_date))
        ->addAttributeToFilter('status', array('eq' => Mage_Sales_Model_Order::STATE_COMPLETE));

    foreach($orderCollection as $order){
       $items = $order->getAllVisibleItems();
       foreach($items as $i){
         echo $i->getProductId();

hope it will helpful to you


To solve your problem you can use Zend_Date objects.

$fromDate = new Zend_Date('2016-3-5');
$toDate = new Zend_Date('2016-3-10');

And use these parameters in your filter

... array('from'=>$fromDate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),
      'to'=>$toDate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)) ...

And to check your query is ok you have to invoke the __toString method of the collection select

echo $orderCollection->getSelect();

To bring this answer up to date using the datetime object - this example gets orders between 01.01.2018 and today.

    $_fromDate = new \DateTime('2018-01-01');
    $_toDate = new \DateTime();

    $_collection = Mage::getResourceModel('sales/order_collection')
        ->addAttributeToFilter('created_at', array('from'=>$_fromDate->format('Y-m-d H:i:s'), 'to'=>$_toDate->format('Y-m-d H:i:s')))
        ->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getId())
        ->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
        ->setOrder('created_at', 'desc')

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.