Mauro Alexandre
Mauro Alexandre

Reputation: 121

How to modify MySQL CURRENT_TIMESTAMP

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.

Enviroment

What did I so far?

I've modified local time to date I need and RTC as well.

OS time

Upvotes: 0

Views: 227

Answers (1)

matigo
matigo

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

Related Questions