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

nirod's avatar
Level 3

MariaDB Carbon wrong timezone / hour missing

Hello together, i have a problem with reading a date from my database with carbon

Setup: model.php

protected $dates = ['dateField']

if i get the value, its one hour behind

model::find(1)->dateField //2023-02-23 23:00:00

If i turn off protected $dates... and get the raw value, its a correct string

2023-02-24 00:00:00

So writing to the table is correct.

I set the config/app.php

'timezone' => 'Europe/Berlin',

and in my php.ini

date.timezone = Europe/Berlin

The timezone is set correctly

Config::get('app.timezone') //Europe/Berlin

Why is this one hour missing? Is there a misconfiguration somewhere? Thanks for your help :)

0 likes
4 replies
LaryAI's avatar
Level 58

It looks like you have the correct timezone settings, so the issue may be related to the MariaDB server. Try setting the timezone for the MariaDB server to the same timezone as your application. You can do this by running the following command in the MariaDB console:

SET GLOBAL time_zone = 'Europe/Berlin';

If that doesn't work, you can also try setting the timezone for the connection when you create it. You can do this by adding the following line to your database config file:

'options' => [PDO::MYSQL_ATTR_INIT_COMMAND => "SET time_zone = 'Europe/Berlin'"]
nirod's avatar
Level 3

Yes i checked already:

SHOW SESSION VARIABLES LIKE 'time_zone';
this table gets returned:
|Variable_name | Value
|time_zone | SYSTEM

and also when i run

SELECT NOW(); //correct time right now in my timezone
nirod's avatar
Level 3

Update: When i run

Carbon::now();
or
Carbon::now('Europe/Berlin');

It's also both times one hour behind. So its no mysql issue. Hm but where is the misconfiguration...

Btw the server time is also set corectly

nirod's avatar
Level 3

Update: It's so strange:

$date = Carbon::now();
return response()->json([
        'test' => $date->format('Y-m-d H:i:s e'),
        'test2' => $date
    ]);

This get's returned:

 {"test":"2023-03-01 13:16:40 Europe\/Berlin",
"test2":"2023-03-01T12:16:40.668210Z"}

What's wrong here? :(

Please or to participate in this conversation.