Question

I am trying to display created date column in CGridView, in DB its datatype is DateTime. I have used the below code to format the date,

array(  'name'=>'created',
                        'header'=>'created',
        'value' => 'Yii::app()->dateFormatter->format("d/M/y",strtotime($data->created))'
                       ),

I am getting date formated column in CGridView, but null values shows sysdate in column. Please see attached image,

Please provide any solution to remove sysdate in null values column

enter image description here

Was it helpful?

Solution

Well, strtotime(null) will return false (Kami is apparently wrong).

The issue is in Yii date formater : Yii::app()->dateFormatter->format("d/M/y", false) will return current date.

You should simply create a getter in your model :

function getCreatedDate()
{
  if ($this->created===null)
    return;

  return Yii::app()->dateFormatter->format("d/M/y", $this->created);
}

And in your grid view columns, you just have to use :

  • array('name'=>'created', 'value'=>'$data->createdDate'),
  • or 'createdDate'.

OTHER TIPS

Use nullDisplay property of CGridView and set:

'nullDisplay'=>''
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top