Yii Framework Forum: CFormatter datetime configuration in CDetailView? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CFormatter datetime configuration in CDetailView? Rate Topic: -----

#1 User is offline   smclark89 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 20-June 09
  • Location:NY, USA

Posted 12 July 2010 - 07:39 PM

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?
0

#2 User is offline   smclark89 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 20-June 09
  • Location:NY, USA

Posted 15 July 2010 - 02:47 PM

Bump :)
0

#3 User is offline   PrplHaz4 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 28-September 09
  • Location:Boston, MA

Posted 15 July 2010 - 09:48 PM

per http://www.yiiframew...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","")',
        ),

0

#4 User is offline   saebaryo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 13-October 10
  • Location:jogjakarta - Indonesia

Posted 29 November 2010 - 04:50 PM

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),
		),
	),
)); ?>

everything must standing on balance
0

#5 User is offline   Mukke 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 05-September 09
  • Location:Brussels (Belgium)

Posted 24 January 2011 - 06:08 AM

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
(\ /)
( . .)
C('')('') -- This is Tiny Bunny. Copy Tiny Bunny into your signature to help him on his way to world domination.
Posted Image
0

#6 User is offline   thiromi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 17-March 11

Posted 27 June 2011 - 10:09 AM

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!

This post has been edited by thiromi: 27 June 2011 - 10:11 AM

0

#7 User is offline   xlap 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 03-April 12
  • Location:UK

Posted 29 March 2013 - 10:17 AM

View Postthiromi, on 27 June 2011 - 10:09 AM, said:

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 :).

This post has been edited by xlap: 29 March 2013 - 10:30 AM

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users