Wednesday, March 15, 2017

Date Changes when retrieved from MySQL database

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



via Jake M

Advertisement