Change Timezone Shared Hosting – PHP / MySQL

To change the timezone within a shared hosting, where you cant change the MySQL’s timezone, you need to execute a query which needs to be run after every MySQL you connect for database.

Change Timezone Shared Hosting

If you have a shared hosting, or due to any other reason, where you cannot change the MySQL’s timezone, here is what you need to do to fulfill your need of changing the timezone.

In the connection file, or whichever file where you connect to MySQL database, simply run the following query after you connect to the database.
SET time_zone = '-6:00';

In PHP, you could write the code below:
mysql_query("SET time_zone = '-6:00'");

By executing the above query, your connection’s timezone will be decreased to -6 hours as per the actual timezone is set over there in the database.

Check Current Timezone – MySQL

To check MySQL’s current timezone, write the following query, which will return you the difference of GMT and the current timezone of MySQL:

SELECT TIMEDIFF(NOW(), CONVERT_TZ( NOW(),@@session.time_zone,'+00:00' ) );

By checking the timezone of MySQL, you can easily manage the difference of GMT and can set your current timezone in PHP connection, which you want.

  1. Hi are you mean php.ini add
    mysql_query(“SET time_zone = ‘-6:00′”); ??

    I am also sharing host, time different make me confuse.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>