You have to run $productData = $this->_filterDates($productData, $dateFields);
for dates and _filterDateTime
for datetime values on them. To make a mysql-readable format out of them, before saving
All magento transaction data it's saved in UTC so you need to start with the UTC now not your store or server now.
To get the NOW in UTC you can use:
// Get Store ID
$store = $this->getCurrentStoreId(); // You can change it
// Get Store Now (Zend_Date)
$nowStore = Mage::app()->getLocale()
->storeDate($store, null, true);
// Get Store Now (String)
$nowStoreDatetime = $nowStore->toString('y-MM-dd HH:mm:ss');
// Get Now UTC
$nowUtc = Mage::app()->getLocale()
->utcDate($store, $date, true);
Now you can play with Zend_Date:
/** @var Zend_Date $nowUtc */
$nowUtc->subHour(1);
$finalDatetime = $nowUtc->toString('y-MM-dd HH:mm:ss');
Using $finalDatetime
in your query you should get the orders you want.
Note that updated_at
date can change if you add a comment to the order or some cron/payment gateway do something, so if you want to track the exactly moment that the order was set to 'pending' you should add a join with status_history
table. If that were your case, just let me know and i'll update the answer.
EDIT
Adding a Join with Sales_Order_Status_History to filter by the date when the order was set as 'pending'.
$orders = Mage::getModel('sales/order')->getCollection()
$select = $orders->getSelect();
$select->join(
array('sfosh' => 'sales_flat_order_status_history'),
'sfosh.parent_id = main_table.entity_id',
array()
)
->group('main_table.entity_id');
$orders
->setOrder('sfosh.created_at', 'ASC')
->addFieldToFilter('sfosh.created_at', array('lteq' => $finalDatetime))
->addFieldToFilter('main_table.status', array('eq' => 'pending'))
;
Best Answer
You can use an instance of Timezone to convert it into store's timezone. Here is a very generic example.