Date & Time Formatting

In mySQL:




Table: News

Field: datestamp

Field Type: date



In View:




<?php foreach($news as $row): ?>

<h3 class="h3_2"><?php echo $row->datestamp ?></h3>



Returns "2009-11-22"

I would like to format as "11/22/2009". What is the best way to accomplish this?

I can use


<?php echo Yii::app()->dateFormatter->formatDateTime($row->datestamp, 'long', '') ?>

but the format is not quite what I want and seems quite long to put in the view.

I tried to use CDateFormatter::format(‘mm/dd/yyyy’, $row->datestamp) but get a different error.

1. Should I or can I do this at the "News" activerecord model level?

2. Why is there not an easier formatting function since this is a common need?

Thanks!

TL

I don’t know if it can help you, but did you have try this: http://www.yiiframework.com/extension/time/#doc ?

This should work




<?php $df = new CDateFormatter('en_us'); echo $df->format('MM/dd/yyyy', $row->datestamp); ?>

or

<?php echo Yii::app()->dateFormatter->format('MM/dd/yyyy', $row->datestamp); ?>



/Tommy

See this

extension - i18n-datetime-behavior