OpenCart is an online store management system which is freely available under the GNU General Public License. It is PHP-based using MySQL database and HTML components. It is a well known simple and light weight eCommerce platform used to make small to medium size eCommerce website. It is a well-designed user interface with a higher selection of extensions.

OpenCart is used globally and operated from different timezone based on the site owner’s place. In most of the cases, OpenCart site run in UTC timezone. This can affect all the aspects that depend on the time zone such as product comment, special price to order history.

To Change the PHP Timezone:

 The PHP time zone can be changed in two methods through php.ini or set them directly at PHP file.

1) To change the timezone in php.ini, seek the help from the hosting provider as one host to another have a different approach.

2) Use the following code and change the system/startup.php with PHP supported timezone.

if (!ini_get('date.timezone')) {

date_default_timezone_set('UTC');

}

date_default_timezone_set('Australia/Sydney');

In the above code, ‘date.timezone’ was configured in php.ini and the time zone will be changed. Make sure that after changing the PHP timezone, synchronize it with the database.

To Synchronize PHP and Database Timezone:

To synchronize the PHP and database timezone, set the database connection timezone. The global database timezone can be set but that needs super-privileged user which will not be available on shared hosting. The following query is used to set the database timezone

SET time_zone='offset';

Here offset and not named timezone is used because the named time zones can be used only if the time zone information tables in the MySQL database are created and populated.

To change the OpenCart database connection time zone, change the system/library/db/mysqli.php and add the following code after $this -> connection -> query(“SET SQL_MODE=””);

$dt = new \DateTime();

$this -> connection -> query("SET time_zone = ' ".$dt->format('p')." ' ; ");

In the OpenCart version 2.0x and 2.1x, change $this -> connection to $this -> link.

Before checking the result, refresh the modification at Extensions > Modification as the system information use OcMod to get the database information.