Formatting column with date in different format



In the beginning of this page there is only an example of formatting column with date, using PHP date()function, therefore requiring a timestamp (integer, number of seconds that passed since Unix Epoch, see PHP manual for more details).

Here is an example how to format column, when you receive date in it and you only want to reformat it (as converting received date to timestamp and them back to date with different format might be a real pain in the a..). It is using procedural approach to PHP's DateTime class

$this->widget('zii.widgets.grid.CGridView', array
(
'id'=>'zlecenia-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array
(
'ID',
array
(
'name'=>'DATR',
'htmlOptions'=>array('style'=>'text-align: center'),
'value'=>'date_format(date_create($data->DATR), "Y-m-d H:i:s")',
),
),
));