Started by Peter DanielsSep 25, 2021

How to change the server time zone without affecting already inserted data?


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?

1 Replies

Techiio-commentatorNeel Dey replied 4 months ago0 likes0 dislikes

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.

You must be Logged in to reply

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance