Magento order created with the wrong date

I am trying to get all orders in magento, starting with a user-defined number entered.

$orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('created_at', array('from' => $userdate)); 

But he does not draw out the right orders. If I use today's date, it pulls half of the orders from yesterday and half from today.

After a bit of googling, it looks like the two dates are stored in Magento

 $order->getCreatedAt() 

UTC / GMT seems to be

 $order->getCreatedAtStoreDate() 

Gives the same time as in the interface (i.e. my local timezone).

If I'm right in what I found, then how can I add an AttributeToFilter using CreateAtStoreDate. I tried

 ('created_at_store_date', array('from' => $userdate) 
+4
source share
1 answer
 <?php ini_set('display_errors',true); include 'app/Mage.php'; Mage::getIsDeveloperMode(true); Mage::app(); $formatStr = 'Ymd H:i:s'; $startStr = 'Yesterday 12:00:00AM'; $endStr = 'Yesterday 11:59:59PM'; $date = Mage::getSingleton('core/date'); /* @var $date Mage_Core_Model_Date */ $collection = Mage::getResourceModel('sales/order_collection'); $collection->getSelect() ->where( sprintf("created_at BETWEEN '%s' AND '%s'", $date->gmtDate($formatStr,$startStr), $date->gmtDate($formatStr,$endStr) ) ); $collection->load(true); 
+3
source

Source: https://habr.com/ru/post/1438805/


All Articles