date in CGridView

Hello everyone.

I have this code:

$this->widget('zii.widgets.grid.CGridView', array(







	    'header'=>'Дата народження'










It works Ok, but in my database there are many fields with date ‘0000-00-00’ and in my table generated by CGridView widget this date appears as ‘01.01.1970’. What should I do to replace ‘0000-00-00’ with empty string so that ‘01.01.1970’ would not appear when date is all zeros?


Just check for that value…

Something like

'value'=>'$data->dn=="0000-00-00" ? "empty date" : date("d.m.Y",strtotime($data->dn))',


Thank you guys. Both your solutions work great.

You can also write a getter method, as probably you will use this standard in more places (views, for example):

So in the model:

public function getSafeDate()


   if ($this->dn=="0000-00-00")

       return 'empty date';


       return date("d.m.Y",strtotime($data->dn));


And in your grid view you can use:


This allows you, for exapmle, to change the string ‘empty date’ in one place.

Thank you, zaccaria, I find your suggestion very valuable.