1

while displaying data from database in my yii webapp i want to change the date format of my date column from yyyy-mm-dd to dd-mm-yyyy ..

code in my view for date of birth column.

<?php echo CHtml::encode($data->getAttributeLabel('Date Of Birth')); ?>
<?php echo CHtml::encode($data->dob); ?>

2 Answers 2

1

Can you try this,

 Yii::app()->dateFormatter->formatDateTime(
                CDateTimeParser::parse(
                    $data->dob, 
                    'dd-mm-yyyy'
                ),
                'short',null
            );

Ref: http://www.yiiframework.com/wiki/183/using-international-dates/

http://www.yiiframework.com/doc/api/1.1/CDateFormatter

Sign up to request clarification or add additional context in comments.

Comments

0

You can use DateTime

  • Create a DateTime object with the value you have now
  • Reformat the object to the desired format.
<?php

$date = DateTime::createFromFormat('Y-m-d', $data->dob);
echo $date->format('d-m-Y');

https://eval.in/205827

2 Comments

You're welcome - However, as you're using Yii, it may be worthwhile using @KrishR answer. (I've never used Yii, so...)
Ah okay :) I'm glad I gave an alternative solution then

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.