Magento – How to set Local Timezone when saving time into DB in Magento

magento-1.9timetimezone

I have applied following things to make Default time zone to my local timezone i.e. 'Asia/Calcutta'

1) changed in config.xml –

<general>
            <locale>
                <code>en_US</code>
                <timezone>Asia/Calcutta</timezone>
            </locale>
 </general>

2) Changed in Mage.php –

 if (is_readable($localConfigFile)) {
                $localConfig = simplexml_load_file($localConfigFile);
                date_default_timezone_set('Asia/Calcutta');
                if (($date = $localConfig->global->install->date) && strtotime($date)) {
                    self::$_isInstalled = true;
                }
  }

Now when I am trying to insert any time in db using this code

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

it does not work according to current timezone and saves 5:30 hours ahead date in DB. can anyone tell me how can I do it or Have I done something wrong in default timezone settings.

Best Answer

I believe what you need to do it go to System > Configuration > General > General > Localization options and change the default timezone to "India Standard Time" then Save.
I think this is what prevents you from having the right time saved in the DB.

Related Topic