Reputation: 131
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
Upvotes: 0
Views: 2181
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')
,'createdDate'
.Upvotes: 2
Reputation: 12101
Use nullDisplay property of CGridView and set:
'nullDisplay'=>''
Upvotes: 0