TMKS
TMKS

Reputation: 131

Date Format issue in CGridView - YII Framework

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

Upvotes: 0

Views: 2181

Answers (2)

soju
soju

Reputation: 25312

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'.

Upvotes: 2

voodoo417
voodoo417

Reputation: 12101

Use nullDisplay property of CGridView and set:

'nullDisplay'=>''

Upvotes: 0

Related Questions