Hi,
I’m trying to parse date to format using CDateTimeParser but it always returning false.
See my example here:
$l = Yii::app()->getLocale();
echo date('Y-m-d', CDateTimeParser::parse('2013-06-03', $l->getDateFormat('short'))) . "\n";
Hi,
I’m trying to parse date to format using CDateTimeParser but it always returning false.
See my example here:
$l = Yii::app()->getLocale();
echo date('Y-m-d', CDateTimeParser::parse('2013-06-03', $l->getDateFormat('short'))) . "\n";
Hi VINAY Kr. SHARMA,
Check the return value of “$i->getDateFormat(‘short’)”, and you will see a string that you didn’t expect.
And check the locale information under "framework/i18n/data".
My Locale is ‘en_IN’.
$i->getDateFormat('short');
returns this
dd/MM/yy
I see.
“dd/MM/yy” is the expected result of “getDateFormat(‘short’)” for en_in, because framework/i18n/data/en_in.php line 161 reads as the following:
'dateFormats' =>
array (
'full' => 'EEEE d MMMM y',
'long' => 'd MMMM y',
'medium' => 'dd-MMM-y',
'short' => 'dd/MM/yy',
),
And CDateTimeParser can’t parse ‘2013-06-21’ with the short date format of en_in.
So, what to do?
Is this a bug of framework?
Not a bug.
CLocale::getDateFormat is working just fine.
And CDateTimeParser too is working as expected … it must return false when the string is ‘2013-06-21’ and the format is ‘dd/MM/yy’.
Just supply the appropriate format.
echo date('Y-m-d', CDateTimeParser::parse('2013-06-03', 'yyyy-MM-dd')) . "\n";
Or, do you have to parse the date strings with various formats?
You may want to explain your needs in a broader context.