Simon R
Simon R

Reputation: 3772

Timezone issue in Lumen

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.

Upvotes: 4

Views: 2552

Answers (2)

Ankur Garg
Ankur Garg

Reputation: 605

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

Upvotes: 0

Simon R
Simon R

Reputation: 3772

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.

Upvotes: 6

Related Questions