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

Stratos's avatar
Level 14

Laravel saving timestamps as UTC but MySQL server is also adding an extra offset.

So my laravel app is configured to save timestamps as UTC and that is fine. I see them saved 5 hours ahead (because im GMT-5) but they're really saved as 10 hours ahead because MySQL is also adding a 5 hours offset somehow.

Is there a way to prevent MySQL from doing this? is it a phpmyadmin's fault ?

0 likes
2 replies
Stratos's avatar
Stratos
OP
Best Answer
Level 14

I'm gonna go ahead and answer this if anybody else stumbles upon this.

By default config/app.php comes with

'timezone' => 'UTC',

Which will store any timestamp as UTC. This is correct.

Also, the MySQL database connection is most likely using the server's timezone where it is located. This could be anything depending on the server. This is wrong.

An UTC timestamp should be stored as UTC in the database, but MySQL is offsetting this by using its timezone value. If you're trying to retrieve an UTC timestamp to convert to a different timezone later on, per your application or each individual user settings, it'll come with an added offset, because it was not originally stored as UTC.

To prevent this, go to config/database.php and set the connection offset to +00:00:

'mysql' => [
            'driver' => 'mysql',
            ...
            'timezone'  => '+00:00',
        ],

This way the database connection will also obey an UTC setting and it'll prevent from adding unwanted offsets.

Note When viewing the data through phpmyadmin or command line it will still be converted to the server's local timezone because of the client behaviour. To view the data as UTC timestamps, remove the unwanted offset it like this:

SET time_zone = "+00:00";
SELECT * FROM `my_table`;
13 likes
docentik's avatar

Hi.

But how can i format data to specific Timezone for all models?

Please or to participate in this conversation.