0

I am working on a Laravel application that has the timezone set to UTC in the config/app.php and config/database.php files, and the timezone on the MySQL server is set to America/Denver and cannot be changed there because we have multiple apps using that server.

The problem is, when saving a new model with timestamps, the created_at/updated_at are set in the America/Denver timezone, when I need them to use the UTC timezone. I have played around quite a bit and have tried the following with no luck:

Made sure that the timezone settings were not incorrectly cached as suggested here and here:

$ php artisan cache:clear    
$ php artisan view:clear
$ php artisan config:cache

Set my PHP script timezone to UTC as suggested here and here and outlined here:

date_default_timezone_set('UTC')

Set the MySQL session timezone to UTC as suggested here and outlined here:

DB::statement("SET time_zone='UTC';")
DB::select('SELECT @@global.time_zone, @@session.time_zone;')

I'm out of ideas. Any suggestions would be great!

David
  • 65
  • 1
  • 11

1 Answers1

0

Alright...

It appears that my dates are indeed stored in UTC but are displayed in local time... I was not expecting this behavior as I come from a SQL Server background and have never encountered this before. I tested that this is in fact the case by creating a few model records, then selecting them back out using UTC, and received the correct records. Seems to be good to go, just a bit confusing. If you have an explanation as to why MySQL will store datetimes in UTC but displays them in the local server time, that would be helpful!

Thanks!

David
  • 65
  • 1
  • 11