iwanzijderveld's avatar

Timezone Europe/Amsterdam doesnt insert correct time in database

I've set APP_TIMEZONE to Europe/Amsterdam, but when I instert a record into the database it inserts with 1 extra hour. It worked fine before

0 likes
7 replies
divanoli's avatar

run now() in artisan tinker to see if it shows the correct time? Probably something related to daylight savings?

1 like
iwanzijderveld's avatar

I think it's related to daylight savings yes. I'm on Lumen so tinker is not installed by default I installed vluzrmos/tinkerand get the following message when I run the command Psy Shell v0.8.15 (PHP 7.1.4 — cli) by Justin Hileman now() PHP Fatal error: Call to undefined function now() in eval()'d code on line

divanoli's avatar

I think Lumen does not have a function now(). Try Carbon\Carbon::now() instead.

gregrobson's avatar
Level 6

Note that depending on database implementation timestamps might appear as UTC+offset. E.g. a local time of 15:34 for Europe/Amsterdam might appear as 14:34+01:00 in the database.

Can you select the value in the database as a UTC value? (I don't know what DMBS you are using.) In the above example you should just get the 14:34 back.

divanoli's avatar

@iwanzijderveld

You can test if its your database implementation problem by typing NOW() in your datetime field through SequelPro or phpMyAdmin. See if it shows the same time.

iwanzijderveld's avatar

@divanoli when I user Carbon\Carbon::now() I get Carbon\Carbon {#482 +"date": "2017-11-29 10:56:59.772623", +"timezone_type": 3, +"timezone": "Europe/Amsterdam", } which is correct with the time right now. So that means it's a database implementation problem right? I'm using the standard MySQL database provided by XAMPP

divanoli's avatar

connect to your database with phpmyadmin and go to that table. insert a new record. put NOW() in datetime field. check that result as well

Please or to participate in this conversation.