Storage of Datetime with Timezone Information in MySQL
Storing dates and times in a database, especially when dealing with different timezones, can be challenging. This is particularly true when there are colaboradores accessing data who may be located in various timezones.
To overcome this issue, it's crucial to establish consistency in storing datetime information. One solution is to utilize the DATETIME datatype in MySQL instead of the TIMESTAMP datatype. Unlike TIMESTAMP, which converts values to UTC for storage and retrieval, DATETIME does not perform this conversion. By storing datetime values as DATETIME, you ensure that they remain untouched and will be displayed in the intended timezone.
To illustrate this, let's consider the example provided in the question. Using DATETIME, the following command would successfully insert the datetime value "2011-03-13 02:49:10":
This time, you would not encounter the error related to "incorrect datetime value" because the value is preserved in its original timezone without being converted to UTC.
The above is the detailed content of How to Properly Store Datetime with Timezone Information in MySQL?. For more information, please follow other related articles on the PHP Chinese website!