How to Change OpenCart Timezone

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.

about author

Sam

samatwwc@gmail.com

WordPress, Magento, cPanel, Plesk, WHM, WooCommerce

Leave a Reply

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