Reputation: 121
In my application I have a field called created_at
predefined as CURRENT_TIMESTAMP
. My all application (PHP) is configured to timezone America/Recife -03
, but when I insert a data it's saved to another timezone, e.g current time is 20:34 and it's saved as 11:34.
I've modified local time to date I need and RTC as well.
date
output: Sat May 1 20:42:05 -03 2021timedatectl
output: Local time: Sat 2021-05-01 20:42:16 -03
, Universal time: Sat 2021-05-01 23:42:16 UTC
, RTC time: Sat 2021-05-01 20:42:16
, Time zone: America/Recife (-03, -0300)
Upvotes: 0
Views: 227
Reputation: 1461
Based on MySQL’s documentation regarding the timestamp
data type:
MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval. (This does not occur for other types such as DATETIME.) By default, the current time zone for each connection is the server's time. The time zone can be set on a per-connection basis. As long as the time zone setting remains constant, you get back the same value you store. If you store a TIMESTAMP value, and then change the time zone and retrieve the value, the retrieved value is different from the value you stored.
If you are doing some sort of time zone manipulation outside of the database, it may be messing up your timestamp values, hence the 9-hour difference.
Upvotes: 2