Grid view display date in wrong timezone?

Hi all,

I’m using a grid view to display a date stored into the database with timezone set to Europe/Rome. When the grid is displayed, you can see the time two hours forward than the time stored into the database. As example, I have a row into the database with time 23/08/2015 16:44:23. The grid shows 23/08/2015 18:44:23. I set up the format of the column as ‘format’ => [‘date’, ‘php:d-m-Y H:i’], but nothing change if I remove the format option to the grid. The only way to display the date correctly is to create a new query using db\Query object and in select statement specify the mysql DATE_FORMAT function in this way: DATE_FORMAT(q_template.datains,‘d/m/Y H:i:s’).

Could you help me to understand why the grid view won’t show the right values?

Thank you!!

I guess your database stores the time as UTC while your local displayed time is +2 hours.

Read more about how to configure it here: http://www.yiiframework.com/doc-2.0/guide-output-formatting.html#time-zones

Thank you very much Bizley.

Setting under main.php file the default time zone for formatter components it displays the right date and time…

Thank you again.