I'm using the YII framework... and I am displaying my date using the following code:
<?php echo $classified->created_date ?>
Problem is that it shows it like this: 2012-11-04 09:34:03
How can I remove the time and just show the date?
And maybe if possible show it like this: 20 Jan 2012 (with the month shortened)
You can use Yii's CFormatter
class:
echo Yii::app()->format->date(strtotime($classified->created_date));
You can extend CFormatter into your own class, and then format the date however you would like, you would just need to include your new component class in the main config file.
Another option is using Yii's date parser and dateFormatter:
echo Yii::app()->dateFormatter->formatDateTime(CDateTimeParser::parse($classified->create_date, 'yyyy-MM-dd'),'medium',null);
There are many ways to do this... You can use standard PHP if you want to. The only draw back to this is that if you decide to change formats, you may have to change many different views:
echo date("m/d/Y",strtotime($classified->create_date));
Yii::app()->dateFormatter->formatDateTime($classified->created_date, 'medium', false);
more examples for date format look here : http://www.yiiplayground.com/index.php?r=InternationalizationModule/datetime/basic
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With