Receive orders in the last 24 hours at Magento

I try to get all order items in the last 24 hours. My request is blocked, so it returns me what I need (value of order_id and created_on).

$order_items = Mage::getResourceModel('sales/order_item_collection') ->addAttributeToSelect('order_id') ->addAttributeToSelect('created_at') ->addFieldToFilter('sku', $membership_sku) ->toArray(); 

I searched everything and it seems to me that I need to add another property -> addFieldToFilter (), but I'm not quite sure how it should be structured. Any examples would be extremely helpful.

If this helps, I use Magento Enterprise v1.12.0.2

+8
magento
source share
2 answers

I think you will need to reformat your time to get good results:

 $time = time(); $to = date('Ymd H:i:s', $time); $lastTime = $time - 86400; // 60*60*24 $from = date('Ymd H:i:s', $lastTime); $order_items = Mage::getResourceModel('sales/order_item_collection') ->addAttributeToSelect('order_id') ->addAttributeToSelect('created_at') ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to)) ->load(); 
+15
source share

After some additional research, I came across the documentation here . I decided to use strtotime as it is simpler, however if someone has a better solution, let me know.

 ->addFieldToFilter('created_at', array( 'from' => strtotime('-1 day', time()), 'to' => time(), 'datetime' => true )) 
+13
source share

All Articles