[SOLVED] How to display the time field value in hh:mm format and not display the seconds.

hello everyone.

I am using this extension http://www.yiiframework.com/extension/ejuidatetimepicker/ to retrieve the time field value and my form is


<?php 

        $this->widget('common.extensions.timepicker.EJuiDateTimePicker',array(

            'model'=>$model,

            'attribute'=>'end_time',

            'timePickerOnly' => 'true',

            'options'=>array(

                'timeFormat' => 'h:m',

                'changeMonth' => true,

                'changeYear' => false,

                ),

            ));  

        ?>

but it saves the time in hh:mm:ss format. the time field type in database table is TIME and I want that on frontend view it should display the time in hh:mm format.

So how can I do this ?

Thanks in advance.

Use the following code in your _view.php:

<b><?php echo CHtml::encode($data->getAttributeLabel(‘doe’)); ?>:</b>

&lt;?php echo date(&quot;d-m-Y H:i&quot;, strtotime(CHtml::encode(&#036;data-&gt;doe))) ?&gt;

<br />

If you want to display the same in some other view(page) do let me know.

thank you dear for your reply. but I have solved it by myself. thanks a lot dear.

well one thing that is left is to set the AM/PM option with the time e.g. 3:45 PM or 9:19 AM etc.

Just add "A" if you want to display AM/PM or "a" to display in lower case am/pm.

<?php echo date("g:i A", strtotime(CHtml::encode($data->doe))) ?> //"g" gives a 12 hour time format

Click the plus button if you think my solutions are helping you out. :D

http://au2.php.net/manual/en/function.date.php