CGridView create_time formatting

I am using the formatting ‘value’=>‘date(“M j, Y”, $data->create_time)’. I have a value in create_time, but when I use the expression, it is zero (i.e., expression returns Dec, 12 1969).

The formatting code for this is right out of http://www.yiiframework.com/doc/api/1.1/CGridView

For now, to remove the time stamp I used substr. But with this, I cannot format the date. Here’s my code (the commented out data expression is what is not working:

‘columns’=>array(

'id',


    'title',


	array('header' => 'date',


		'value' => 'substr($data->create_time,0,10)'), //'date("M j, Y", $data->create_time)'),

Any ideas? Is this working for anyone else?

I had a problem with this also… didn’t have time to debug, so I just created a method and used it:




    'value' => 'MyModel::model()->displayDate($data->create_time)',



*Edit - I just tested this and whatever problem I had has gone away.

Hello

I don’t get it. You say create_time is a timestamp? Like a Unix one: ‘1343392756’, or a date: ‘2012-07-29’?

Its a timestamp. If its a regular date, you must use strtotime():




    date("M j, Y", strtotime($data->create_time))



That’s the ticket! Thank you! And yes, it is a timestamp from MySQL default value.