I have a query that retrieves a date from my database. My problem is the date changes from what is stored in the database.
In the database the date is 2017-01-31 23:01:00
. When I retrieve it from the database and echo
the date it is now 2017-02-01 01:01:00
.
What is causing this change and how can I fix it?
My code is below. The code is in a Laravel controller class:
$test_data = UserTest::where('test_id', '=', $id)
->where('user_id', '=', $userId)
->select('date')
->get();
echo $test_data[0]->date; // outputs: 2017-02-01 01:01:00
Edit: In Laravel config/app.php
my timezone setting is: 'timezone' => 'Australia/Melbourne',
. My PHP.ini has date.timezone = UTC
.
In config/app.php you can set your default timezone
'timezone' => 'Australia/Sydney', // or simply 'UTC'
The records you saved previously would still be offset. But those you save from now on will be correct.