date format shows wrong date in GridView

Im just using the following in my GridView within the "columns"




        'columns' => [

            ['class' => 'yii\grid\SerialColumn'],


            //'player_id',

            'first_name',

            'last_name',

            [

                'header' => 'Date of Birth',

                'value' => 'date_of_birth',

                'format' => ['date', 'php: d M Y']

            ],


            ['class' => 'yii\grid\ActionColumn'],

        ],



My dates are in datetime in the DB but they are being displayed wrong. For instance 2001-09-21 00:00:00 in the DB is shown in the app as 20 Sep 2001. All my displayed values seem to be 1 day out.

What have I done wrong?

Have you checked app and db timezones in your config?

Yeah, they are fine I believe. The date unformatted comes back in my app correctly as 21-09-2001. But is displayed as the day before.

I’ve just been using phpmyadmin to work on my Maria DB and I note that if I mkae the datetime 3hours later, so 21-09-2001 03:00:00. So maybe they’re not. I’m not sure why there would be any issue though in retrieving a date in the past. Why would the timezone affect it? 21-09-2001 is the same whatever timezone you’re in?? :unsure:

If you have different timezone between app and db, at time 00:00 if you subtract -1 hour, for example, you go to day before.