4

I have an issue where I have set the timezone in Lumen's config to Europe/London. This has been working perfectly well until the recent change to DST where it is setting the correct created_at and updated_at dates, but when I'm calling the record it is showing the datetimes as though it was UTC and not BST/DST.

In my config/app.php file I have;

...

timezone' => 'Europe/London',

...

In my routes for checking, I have;

$app->get('mytime', function() {
    $now = Carbon\Carbon::now();
   dd($now, date('Y-m-d H:i:s'));
});

which returns

Carbon {#35 ▼
  +"date": "2016-04-14 10:33:15.000000"
  +"timezone_type": 3
  +"timezone": "Europe/London"
}

yet when I pull a record which say should have a created_at date of '2016-04-14 10:00:00' it returns '2016-04-14 09:00:00'.

Any help with this timezone issue would be gratefully received.

2 Answers 2

6

I came across the solution. It transpires there is a variable you need to add to the .env file in Lumen where you're dealing with databases.

DB_TIMEZONE=+01:00

It is likely that you'll need to add a cron job to update that variable on the change to and from DST, as 'Europe/London' is not supported sadly.

1
  • 4
    You can also use DB_TIMEZONE=null to keep the server timezone (which might be synced to Europe/London already
    – Sherbrow
    Jan 4, 2019 at 10:48
0

I have also tried many solution. so the conclusion is:

Just set the difference (between what time is showing and what time you have enter the record.) in .env

e.g. So entry is made on 2016-04-14 10:00:00 and it showing 2016-04-14 15:00:00, then set DB_TIMEZONE=+05:00 in .env

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.