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.

3 Answers 3


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

To set created_at value, try to use:


And to get local created_at value, try to use:

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

Dates should always be persisted normalized in GMT. See


In mysql, a column of the type TIMESTAMP stores time in UTC so the time difference you are seeing is normal. When retrieving the data from the database, it converts it over to the timezone that is set for your server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.