Yii Framework Forum: CGridView create_time formatting - Yii Framework Forum

Jump to content

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

CGridView create_time formatting 'value'=>'date("M j, Y", $data->creat Rate Topic: -----

#1 User is offline   Peter Hayman 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 61
  • Joined: 11-June 12
  • Location:Wake Forest

Posted 28 July 2012 - 08:10 AM

I am using the formatting 'value'=>'date("M j, Y", $data->create_time)'. I have a value in create_time, but when I use the expression, it is zero (i.e., expression returns Dec, 12 1969).

The formatting code for this is right out of http://www.yiiframew...i/1.1/CGridView

For now, to remove the time stamp I used substr. But with this, I cannot format the date. Here's my code (the commented out data expression is what is not working:

'columns'=>array(
'id',
'title',
array('header' => 'date',
'value' => 'substr($data->create_time,0,10)'), //'date("M j, Y", $data->create_time)'),

Any ideas? Is this working for anyone else?
0

#2 User is offline   Backslider 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 363
  • Joined: 23-July 09

Posted 29 July 2012 - 12:05 AM

I had a problem with this also.. didn't have time to debug, so I just created a method and used it:

    'value' => 'MyModel::model()->displayDate($data->create_time)',


*Edit - I just tested this and whatever problem I had has gone away.
We were all once expert at....... nothing.

yii-language-behavior

My Blog
0

#3 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,166
  • Joined: 05-January 12
  • Location:Morocco

Posted 29 July 2012 - 05:59 AM

Hello

I don't get it. You say create_time is a timestamp? Like a Unix one: '1343392756', or a date: '2012-07-29'?
0

#4 User is offline   Backslider 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 363
  • Joined: 23-July 09

Posted 30 July 2012 - 12:08 AM

View Postbennouna, on 29 July 2012 - 05:59 AM, said:

Hello

I don't get it. You say create_time is a timestamp? Like a Unix one: '1343392756', or a date: '2012-07-29'?


Its a timestamp. If its a regular date, you must use strtotime():

    date("M j, Y", strtotime($data->create_time))

We were all once expert at....... nothing.

yii-language-behavior

My Blog
1

#5 User is offline   Peter Hayman 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 61
  • Joined: 11-June 12
  • Location:Wake Forest

Posted 30 July 2012 - 10:28 AM

View PostBackslider, on 30 July 2012 - 12:08 AM, said:

Its a timestamp. If its a regular date, you must use strtotime():

    date("M j, Y", strtotime($data->create_time))



That's the ticket! Thank you! And yes, it is a timestamp from MySQL default value.
0

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