Meshan Raza
Meshan Raza

Reputation: 89

orders between two dates mysql magento

I want to get all orders between two dates

$order_collection = Mage::getModel('sales/order')
                ->getCollection()
                ->addAttributeToSelect('*')
                ->addAttributeToFilter('created_at', array(
                'from' => $FromDate,
                'to' => $ToDate,
                'date' => true,
                ));

if my from date is 2016-10-23 its not getting orders generated at 23/10/2016 00:00:01 to 23/10/2016 00:59:59. Any help please

Upvotes: 0

Views: 1741

Answers (1)

Suman r
Suman r

Reputation: 75

you can get it with below code note: check whether you have placed orders between two dates with the status completed

$Datefrom = '2016-10-10'; /* from date  */
$Dateto = '2016-10-25';   /* to date */

$Orderfrom = date('Y-m-d H:i:s', strtotime($Datefrom));
$Orderto = date('Y-m-d H:i:s', strtotime($Dateto));

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

foreach($orders as $order){
     print_r($order);
}

Upvotes: 1

Related Questions