Opencart time zone change

This tutorial covers how to change the timezone in OpenCart as well as change time of the database.

Go to system/startup.php and find following lines of code:

if (!ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}

Replace with following lines of code by changing to your timezone

date_default_timezone_set('Australia/Sydney');

Synchronize PHP and Database Timezone

The query we use to set database timezone if you are super admin is below:

SET time_zone='offset';

But everyone has no super admin access so need to change in the code level. For that go to system/library/db/mysqli.php if you are using MySQLi and add code below after $this->connection->query(“SET SQL_MODE = ””);

$dt = new \DateTime();
$this->connection->query("SET time_zone='" . $dt->format('P') . "';");

With these changes your timezone in Opencart are changed.

Let us know if you find any issues, thanks a lot.

LEAVE A REPLY

Please enter your comment!
Please enter your name here