1

I'm using Lumen 5.6 and on my local server (I don't have a production server yet) and all my timestamps (created_at, updated_at) are being stored natively in my local timezone (Amsterdam, +02:00). I would like this to be in UTC. I have done a standard lumen install I thought UTC was the default?

I have tried the following .env settings

APP_TIMEZONE='+00:00' #This does nothing no matter what I set it to
DB_TIMEZONE='+02:00' #This gets me UTC by offsetting the offset

These two configurations fail with or without quotes

APP_TIMEZONE='UTC'
DB_TIMEZONE='UTC'

# OR

APP_TIMEZONE='Africa/Timbuktu'
DB_TIMEZONE='Africa/Timbuktu'

I have also tried to explicitly set the timestamp column like so

$password_reset = PasswordReset::create([
    'token' => Str::random(60),
    'email' => $request->input('email'),
    'created_at' => Carbon::now('UTC')->toDateTimeString()
  ]);

and the timestamps in my database are STILL offset by two hours. Highly frustrating. I am aware of all the Laravel fixes, none work. And it appears lumen 5.6 does not use an config/app.php like laravel, its all down to the .env file but nothing is working unless i "hack" the DB_TIMEZONE by "+02:00"

11
  • didn't you try to change 'timezone' => 'Africa/Timbuktu' in config/app.php? May 25, 2018 at 8:42
  • yeah i did but apparently lumen doesnt use that since 5.6 it just uses the .env file. But i yeah i tried that :/
    – MrRed
    May 25, 2018 at 8:43
  • 1
    This is weird, since the default lumen database drivers make a point of NOT adding timezones: github.com/laravel/lumen-framework/blob/5.6/config/database.php Maybe you could create your own config/app.php (since there is one: github.com/laravel/lumen-framework/blob/5.6/config/app.php ) and declare your timezone there as you would with laravel? Or maybe PHP is messing up, have you checked the default timezone in your php.ini?
    – Loek
    May 25, 2018 at 8:43
  • unbelievably it doesnt work, even when adding $app->configure('app'); to the bootstrap/app.php as reccomended to get a custom config/app.php to work in lumen
    – MrRed
    May 25, 2018 at 8:49
  • 1
    Mind = blown. Very interested to see what the problem/answer is.
    – Loek
    May 25, 2018 at 9:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.