CFormatter datetime configuration in CDetailView?

I’m using a CDetailView, and trying to configure a date from a MySQL database using the CFormatter datetime method. How can I specify the format to convert the string to? I know I need to use dateFormat, but I don’t know where to specify this.

Any suggestions?

Bump :)

per http://www.yiiframework.com/doc/api/CDetailView




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

    'data'=>$model,

    'attributes'=>array(

        'title',             // title attribute (in plain text)

        'owner.name',        // an attribute of the related object "owner"

        'description:html',  // description attribute in HTML

        array(               // related city displayed as a link

            'label'=>'City',

            'type'=>'raw',

            'value'=>CHtml::link(CHtml::encode($model->city->name),

                                 array('city/view','id'=>$model->city->id)),

        ),

    ),

));



So, for my dates, this is what it looks like:




        array(            // display StDate using DateFormatter

            'label'=>'Date',

            'value'=>'Yii::app()->dateFormatter->formatDateTime($data->StDate,"short","")',

        ),



you can use native PHP date function ???




<?php $this->widget('zii.widgets.CDetailView', array(

	'data'=>$model,

	'attributes'=>array(   	

    	array(

       			'name'=>'update_time',

       			'value'=>date("d F Y", $model->update_time),

		),

	),

)); ?>



i’m having a similar problem

this works:




this->widget('zii.widgets.CDetailView', array(

	'data'=>$model,

	'attributes'=>array(

		'start:date',


	),

));



now i’m not happy with the standard formating so i tried this:


this->widget('zii.widgets.CDetailView', array(

	'data'=>$model,

	'attributes'=>array(

		'start:date("j/m/Y")',


	),

));

i get an error so i assume it’s not the correct way to do it.

in above post it works fine i know, but why make a shortcut to the date formater if can’t even give along a date format

If you want to configure how the date format should work globally, in de main.php application configs put this on the ‘components’ array:




        'format'=>array(

            'datetimeFormat'=>'d/m/Y H:i:s',

            'datetimeFormat'=>'d/m/Y',

        ),



got that from this link

cheers!

Hello,

I tried your solution but it doesn’t seem to work. I edited it so it looks like this:




        'format'=>array(

            'datetimeFormat'=>'d/m/Y H:i:s',

            'dateFormat'=>'d/m/Y',

        ),



but it still doesn’t work. Does anybody have a clue how to change the way that the date is displayed/formatted sitewide?

Thank you in advance.

EDIT:

I found solution.

in the CDetailView array of the view file that I am altering, after having added the previous code in the main.php file, I use the following code:




'columns'=>array(

    array(

        'name'=>'created_on',

        'type'=>'datetime',

    ),

),



I hope this helps anybody who has the same problem :).