fbpx

Magento / Web Apps

Fix Magento 1.9.x timezone after migration

by ,


We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

The proper server timezone for Magento server (or any out there, really) is UTC.

But often times, I see that server admins neglect that rule. They set server timezone to match with Magento, or worse, their own location. By doing so, they introduce nothing but trouble when the time comes to change server.

How to fix Magento timezone after migration?

Let’s take an original server with server timezone set to Singapore. As a result, all the TIMESTAMP columns in Magento will be offset from UTC by +6 hours.

We need the proper TIMESTAMP columns with UTC timezone values on the new server, post data migration.

The fix would be to simply update all the TIMESTAMP columns by removing the bad offset:

UPDATE sales_flat_order SET created_at = ADDTIME(created_at , '-06:00:00'), updated_at = ADDTIME(updated_at , '-06:00:00');
UPDATE sales_flat_order_grid SET created_at = ADDTIME(created_at , '-06:00:00'), updated_at = ADDTIME(updated_at , '-06:00:00');

We have updated the most important columns. Your mileage might vary depending on a number of plugins you have.

To get all the TIMESTAMP in a database, use the following query:

select * from INFORMATION_SCHEMA.TABLES T where EXISTS 
  (
      select 1 
        from INFORMATION_SCHEMA.COLUMNS 
       where TABLE_CATALOG = T.TABLE_CATALOG
         and TABLE_SCHEMA = T.TABLE_SCHEMA
         and TABLE_NAME = T.TABLE_NAME
         and DATA_TYPE = 'timestamp' -- or the literal representing timestamp data type
         and TABLE_SCHEMA = 'dbname'
  )

TODO: an n98-magerun plugin? 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.