Yii Framework Forum: Date format - Yii Framework Forum

Jump to content

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

Date format Rate Topic: -----

#1 User is offline   elix 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 14-February 12

Posted 14 February 2012 - 11:20 PM

I've searched other the forum for date formatting examples.
I've found some examples and extensions like DateTimeI18NBehavior and FormatDateTimeBehavior. All this stuff looks great but i can't manage to get it work.

so i write this simple code to test the basic idea :
I set language in config/main.php :
'sourceLanguage'=>'fr_fr',
'language'=>'fr_fr',

$date='2012-02-15';
$dateToLocale=Yii::app()->dateFormatter->formatDateTime(CDateTimeParser::parse($date, 'yyyy-MM-dd'),'medium',null);
$dateBackToMySQL=date('Y-m-d', CDateTimeParser::parse($dateToLocale, Yii::app()->locale->dateFormat));

echo 'My date: '.$date.'<br/>';
echo 'Yii::app()->locale->dateFormat = '.Yii::app()->locale->dateFormat.'<br/>';
echo 'My date to locale: '.$dateToLocale.'<br/>';
echo 'My date back to MySQL format: '.$dateBackToMySQL.'<br/>';


Result is :
My date: 2012-02-15
Yii::app()->locale->dateFormat = d MMM y
My date to locale: 15 févr. 2012
My date back to MySQL format: 1970-01-01


After i had a look at CDateTimeParser documentation it seems to be a normal result as CDateTimeParser does not understand pattern MMM.

But as Yii::app()->dateFormatter->formatDateTime used with 'medium' date width returns a date according to the pattern d MMM y, i don't understand how this example and the above extensions mentionned can work. and it seems it should work according to several posts on the forum.

any idea?
0

#2 User is offline   Pravin Gajera 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 137
  • Joined: 25-October 11
  • Location:India

Posted 15 February 2012 - 01:19 AM

Hi

http://www.yiiplaygr.../datetime/basic

check above link.

I think your pattern is wrong (d MMM y ) this replace with pattern d MM y.

Thanks
0

#3 User is offline   elix 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 14-February 12

Posted 15 February 2012 - 04:15 PM

thanks for the link !

so if i understand i have to override the initial patterns related to long, medium,... with one that will be understood by CDateTimeParser?

So that mean that it is now not possible to work with date like : 13 févr. 2012 ?
I mean transform my MySQL date to a format like 13 févr. 2012 and get it back to MySQL format before save action.

thanks
0

#4 User is offline   mem 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 45
  • Joined: 16-December 11

Posted 04 July 2012 - 10:12 AM

View Postelix, on 15 February 2012 - 04:15 PM, said:

thanks for the link !

so if i understand i have to override the initial patterns related to long, medium,... with one that will be understood by CDateTimeParser?

So that mean that it is now not possible to work with date like : 13 févr. 2012 ?
I mean transform my MySQL date to a format like 13 févr. 2012 and get it back to MySQL format before save action.

thanks



I have exactly the same question some months later, can someone please clarify it?
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