Hello Magento Friends,
In today’s Magento 2 tutorial, we will find out How to Get Orders Collection Between a Date Range in Magento 2.
The admin uses order collection to get order details and smoothly fulfill the orders. Sometimes the admin does not want all order collection but needs only specific orders based on filter options.
Suppose you want all orders between a specific date range. You can Get Order Collection Between Specific Date Range in Magento 2 using the below method.
Use the below code in your Root file
<?php use Magento\Framework\App\Bootstrap; ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); require __DIR__ . '/../app/bootstrap.php'; $params = $_SERVER; $bootstrap = Bootstrap::create(BP, $params); $objectManager = $bootstrap->getObjectManager(); $state = $objectManager->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); $now = new \DateTime(); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $OrderFactory = $objectManager->create('Magento\Sales\Model\ResourceModel\Order\CollectionFactory'); $orderCollection = $OrderFactory->create()->addFieldToSelect(array('*')); $fromdate=$now->format('2020-05-01 H:i:s'); $todate=$now->format('2020-06-01 H:i:s'); $orderCollection->addFieldToFilter('created_at', ['lteq' => $todate]) ->addFieldToFilter('created_at', ['gteq' => $fromdate]); echo "<pre>"; print_r($orderCollection->getData()); ?>
This way, you can get all orders from a specific range of dates in Magento 2. Alternatively, Get all Orders of Customers by Email id in Magento 2. If you face difficulty retrieving the order collection of a specific date range, you can connect with me through the comment section.
Happy Coding!
Hello Magento Friends, In today’s blog, I will explain How to Add Tooltip in Checkout…
MongoDB is a popular NoSQL database that offers flexibility and scalability when handling modern web…
In NodeJS, callbacks empower developers to execute asynchronous operations like reading files, handling requests, and…
Hello Magento Friends, In today’s blog, we will learn How to Show SKU in Order…
The "Buy Now" and "Add to Cart" buttons serve as the primary call-to-action (CTA) elements…
Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…