2

I have a PHP project with Mysql database. The problem is the time related data is showing wrong according to my requirements.

I want the timezone should be set to "Time Zone Port louis,Mauritius GMT+04:00".

How to update the timezone so that every data in the database shows the Mauritius timezone? And where to update the timezone?

And if I change the timezone, does the already inserted data automatically updated? Or else how to update the timezones of every record in the database?

Aravind
  • 424
  • 3
  • 19
  • Depends on the datatype of table column where the values are stored. – Akina Sep 23 '20 at 10:36
  • Server timezone should not be altered. Change timezone in .htaccess by adding: php_value date.timezone "Indian/Mauritius" or check here for timezones: https://www.php.net/manual/en/timezones.php – SJacks Sep 23 '20 at 11:37

2 Answers2

3

It is generally a good idea to keep your server in UTC, so that security logs align between computers.

When storing timestamps in a database, it is recommended to use a Timestamp field that includes a timezone. This means that the timezone used by the server is irrelevant.

Also, please note that time conversions are often performed by the SQL Client based upon the locale of the computer that is running the SQL Client. This can often lead to confusion because the time seen in output within the SQL client does not actually match the times stored in columns. (A good way to test this is to cast the field into a Text field, to see the 'raw' value in the field without it being converted by the SQL client.)

I worked in a company that used to set their server to the timezone where the company was located, but as the company grew bigger and they had servers in multiple locations, it became a problem. Thus, it can be better to keep all computers in UTC and specifically convert times when they are being displayed.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
2

you have 3 solutions:

  • you can change the server configuration if you have a dedicated server.
  • change yourself at the level of your applictaion with date_default_timezone_set
  • change yourself at the global level of your php configuration in php.ini
bhrached
  • 127
  • 1
  • 9
  • if I go with the 1st option, does the already inserted data of DB automatically updates their date and time related field data? – Aravind Sep 23 '20 at 10:38