A newbie question in Yii: I have a model of a table in Yii that contain a datetime field.
I'm using CActiveForm to display this field:
<div class="row">
<?php echo $form->labelEx($model,'createdon'); ?>
<?php echo $form->textField($model,'createdon', array('id'=>'createdon')); ?>
<?php echo $form->error($model,'createdon'); ?>
</div>
but the textfield displayed is on datetime format come from MySQL which is yyyy-mm-dd hh:mm:ss
How could I change the format displayed on the textfield to a different time format? (maybe dd/mm/yy or mm/dd/yy or else)
any help would be appreciated.
thanks!
If you want the date stored in one format, but displayed in another format (i.e. multiple views), then consider changing it in the model.
For example:
Which methods you override depends on what you're trying to achieve.
From the docs:
This worked for me:
All you need is to use
CDateFormatter
and it's methodformat
OR you could use native PHP's way to format date using function
date
I think there are lots of examples in
PHP
manual on formatting options (as well as explanation of what each format modifier mean), so it wouldn't be a problem to figure things out, but if you have any problems with Yii'sCDateFormatter
, I can give you some examples.