Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mshafnas's avatar

Created At Timestamp

Hi developers, I am storing records along with the timestamp in mysql. but when I retrive the record the created_at showing a different time instead of database table created_at column's value.

in database the created_at value is 2021-08-12 13:26:32 but when I retrive it is showing as 2021-08-12T07:56:32.000000Z. as you can see the database created_at is something like 1PM but the retrived created_at showing it as 7AM. Can anyone help me to fix this? Thanks

0 likes
3 replies
siangboon's avatar

what we see seem to be datetime format but created_at is timestamp data type as default, there is time zone information in it... check and play around with Carbon, it should serve almost all the purpose you need...

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. This occurs because the same time zone was not used for conversion in both directions. The current time zone is available as the value of the time_zone system variable. For more information, see Section 5.1.15, “MySQL Server Time Zone Support”.

for details: https://dev.mysql.com/doc/refman/8.0/en/datetime.html

1 like

Please or to participate in this conversation.