How to modify MySQL CURRENT_TIMESTAMP

59
May 04, 2021, at 02:50 AM

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

  • OS: [Debian 9 Strech]
  • Database: [10.1.48-MariaDB]

What did I so far?

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

OS time

  • date output: Sat May 1 20:42:05 -03 2021
  • timedatectl 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)
Answer 1

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.

READ ALSO
Render TextAreaField in html with jinja

Render TextAreaField in html with jinja

I am trying to parse config to TextAreaField of python code in htmlBut it displays nothing

30
Reading wav file in Java

Reading wav file in Java

I want to read wav files in Java and I am going to classify them with K-means

51
Is PowerMock using Java agents to instrument Java code?

Is PowerMock using Java agents to instrument Java code?

PowerMock is able to mock final classes because it modifies the bytecodeIs PowerMock using a Java Agent to do that or something else?

67