4

I am trying to change the timezone of my database. I am on shared server and database support guys can not change it for me only. Time zone is currently +1:00 I want it as +05:30. I searched and tried following but nothing worked.

date_default_timezone_set('timezone_name');

Added to my index.php file.

mysql> SET GLOBAL time_zone = 'timezone_name';

It says access restricted.

SET time_zone = timezone_name

Query run now row affected.

My site is hosted on site-ground us server.

psiyumm
  • 6,437
  • 3
  • 29
  • 50
Piyush
  • 3,947
  • 9
  • 36
  • 69
  • 1
    Are you on a shared server?Contact the admin. – Mihai Jan 16 '15 at 09:51
  • Sorry to say but I don't know. – Piyush Jan 16 '15 at 09:53
  • Why do you want to set the timezone global? I would recommend to define the desired timezone for each connection, that way you are save to server side changes. – t.niese Jan 16 '15 at 09:57
  • OK in case you are,hosting is unlikely to want to change the timezone.Another hack is to add the needed interval to your time `+ INTERVAL 4 HOUR` or whatever to your queries.Yeah,it\`s annoying.OR maybe try `SET SESSION time_zone = 'yourtime';` – Mihai Jan 16 '15 at 09:57
  • Yes currently I am doing by modifying quires, but I need to update it on sql. – Piyush Jan 16 '15 at 10:00

3 Answers3

3

Probably you can change the timezone in .htacess without touching your PHP scripts or MySQL query. Open up your .htaccess file, enter the command as below.

SetEnv TZ your_timezone

For example, enter this command if your location in Jakarta

SetEnv ID Asia/Jakarta

Refer to the link below for available timezone:

http://php.net/manual/en/timezones.php

  • Surely that should be 'SetEnv TZ Asia/Jakarta' not 'SetEnv ID Asia/Jakarta' - and this will only work if 'Asia/Jakarta' is known to the timezone database and the webservr is Apache, AND php is running as mod_php. Not to mention the fact that *which* TZ database the PHP install uses depends on the PHP build. – symcbean Jan 18 '15 at 21:40
  • Either `SetEnv ID Asia/Jakarta` or `SetEnv TZ Asia/Jakarta` works fine on me. Sorry, I didn't mention that the command above is an example if you want to set timezone to Asia/Jakarta. I've edited my post. – mirza.adipradhana Jan 19 '15 at 03:34
3

As I am on shared server my provider did not change it only for me. So after search I fount that, I have to use datetime type on sql instead of current time stamp and as madipradhana said I was updated my php.ini or .htaccess .

Piyush
  • 3,947
  • 9
  • 36
  • 69
2

As you are on shared server use date() of php and set date_default_timezone_set('timezone_name'); to your index.php

JoyTree
  • 308
  • 1
  • 8