gifrancohe
(Giovannyfrancoherrera)
April 14, 2016, 8:27pm
1
Hi
I have a problem with date format. In my CGridView I have a date field, this way
2016-04-14 00:00:00
In my BD it is Timestamp, I want to show the date of this form 2016-04-14. I do this in my CGridView follows.
.... //others fields
[
'attribute'=>'fechaingresocolor',
'value'=>'fechaingresocolor',
'format'=>['date','php:Y-m-d'],
]
......
The problem is that if I use this format does not show me the correct date. I shows the date a day ago. For example I have in the BD 2016-04-14 00:00:00 and the CGridView show 2016-04-13.
I hope someone can help me. thanks
Probably this is caused by a different timezone between database and php.
In Yii main/config.php you can set php timezone and db timezone. For example, in this configuration I have set GMT timezone for php and db connection:
'timeZone' => 'GMT',
and go on inside ‘db’ component
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=db_name',
'username' => 'db_username',
'password' => 'db_password',
'charset' => 'utf8',
'on afterOpen' => function($event) {
$event->sender->createCommand("SET time_zone = '+00:00'")->execute();
}
],
gifrancohe
(Giovannyfrancoherrera)
April 15, 2016, 2:43pm
3
Hi Fabrizio Caldarelli
Fabrizio thank you very much that was just what I needed.
'timeZone' => 'GMT',
Regards.