Magento Orders – How Magento Stores Date in Created_at Field

datemagento-1.9orders

I am working on cron extension in which i need to use difference of time. While working on this extension i observed one thing that magento has some difference in time while saving data in the table.

I need to deal with created_at field of sales_flat_order table. to get a time i use following two methods.

Mage::getModel('core/date')->date('Y-m-d H:i:s');
date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()));

when i place a order both of this two method shows time as 2016-05-11 18:04:47 but after placing a order the value for created_at field of sales_flat_order was 2016-05-11 07:04:43.

Can any one please explain me how it is done? How magento insert value for this field?

Note: if i change H with h in above date function then it shows time as 2016-05-11 06:04:47 i.e. 12 Hour time but still their are healthy difference. which affects my functionality.

Thanks in advance.

Best Answer

The Magento uses time relative to the server time, transformed in UTC.

To set created_at value, try to use:

Mage::getSingleton('core/date')->gmtDate();

And to get local created_at value, try to use:

Mage::helper('core')->formatDate($order->getCreatedAt(), 'medium', true);
Related Topic