1

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.

4
  • Why would you do that? Just set the time on your server. Mar 9 '16 at 15:47
  • I have done that already before doing all above. Mar 9 '16 at 16:59
  • Why would you want that? As long as it is converted correct when the data is shown in the backend I think it's fine? Mar 9 '16 at 17:31
  • Then How can I save date in Db in my timezone and other plugins are also using above code to save date in DB. Mar 9 '16 at 18:56
0

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.

4
  • I have already done that. Mar 10 '16 at 8:43
  • ok, create a test.php as the root of your Magento, then load Magento in it and echo date('Y-m-d H:i:s'), tell us what it outputs. Mar 10 '16 at 9:35
  • Yes it shows correct time...But I have to change this code at many place even in other plugins as well which is not good. Mar 10 '16 at 21:00
  • I don't see why you bothered with Mage::getModel('core/date')->date('Y-m-d H:i:s'); in the first place, because PHP's date() will scale with the server's time. I'm sorry but I don't have an answer for your problem then. Mar 11 '16 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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