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

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[SOLVED] How to display the time field value in hh:mm format and not display the seconds. Rate Topic: ***** 1 Votes

#1 User is offline   InsafiaN 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 95
  • Joined: 02-February 14
  • Location:Islamabad, Pakistan

Posted 22 November 2014 - 05:49 AM

hello everyone.
I am using this extension http://www.yiiframew...datetimepicker/ 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.
0

#2 User is offline   S@ndy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 04-September 14

Posted 22 November 2014 - 08:37 AM

Use the following code in your _view.php:

<b><?php echo CHtml::encode($data->getAttributeLabel('doe')); ?>:</b>
<?php echo date("d-m-Y H:i", strtotime(CHtml::encode($data->doe))) ?>
<br />


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

#3 User is offline   InsafiaN 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 95
  • Joined: 02-February 14
  • Location:Islamabad, Pakistan

Posted 23 November 2014 - 11:10 AM

View PostS@ndy, on 22 November 2014 - 08:37 AM, said:

Use the following code in your _view.php:

<b><?php echo CHtml::encode($data->getAttributeLabel('doe')); ?>:</b>
<?php echo date("d-m-Y H:i", strtotime(CHtml::encode($data->doe))) ?>
<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.
0

#4 User is offline   S@ndy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 04-September 14

Posted 24 November 2014 - 01:43 AM

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
1

#5 User is offline   dragan.zivkovic 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 154
  • Joined: 13-September 12

Posted 25 November 2014 - 03:40 AM

http://au2.php.net/m...nction.date.php
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users