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

troelsjohnsen's avatar

Issues when saving and retrieving dates from database

Hi,

I have a problem with an app I am building. I am syncing orders from Shopifys API to a database.

The app has the following timezone: 'timezone' => 'Europe/Copenhagen' The timestamps returned from Shopify is in the following format: 2022-07-04T11:32:18+02:00

When saving the timestamp to the database 2 hours are subtracted and when retrieving the model and outputting the timestamp another 2 hours are subtracted. Like this

Input: 2022-07-04T11:32:18+02:00

Database: 2022-07-04 09:32:18"

Output: 2022-07-04T07:32:18.000000Z

What am I doing wrong?

0 likes
2 replies
JakeCausier's avatar

It looks like the timestamp is attempting to be corrected into UTC, but odd that it's happening twice.

Could you check what your timezone value is set to in your config/app.php file?

troelsjohnsen's avatar

@JakeCausier The timezone is set to timezone => 'Europe/Copenhagen'

I just tried creating a brand new Laravel installation and a simple model with just a timestamp-column. When saving the string 2022-07-04T11:32:18+02:00 it is saved as 2022-07-04 11:32:18. So in the new installation it is not subtracting 2 hours on save.

If the app is set to UTC timezone, it returns when returning the model 022-07-04T11:32:18.000000Z. If the app is set to Europe/Copenhagenit returns when returning the model 022-07-04T09:32:18.000000Z

I am totally confused. If the dates in the database are treated as UTC and Europe/Copenhagen is +02:00. Why is it subtracting 2 hours when returning the dates?

Please or to participate in this conversation.