Reputation: 21
If I have function like this
protected function getAreaValues($model)
{
return
[
[
$model->getAttributeLabel('EXPDATE'),TbArea::findOne($model->KODE)->EXPDATE
],
];
}
where EXPDATE IS date data
How to format it in d-M-Y ?
I add formatter in web.php in config like this
'formatter' => [
'class' => 'yii\i18n\Formatter',
'nullDisplay' => '-',
'dateFormat' => 'd-M-Y',
'datetimeFormat' => 'd-M-Y H:i:s',
'timeFormat' => 'H:i:s',
],
But still not working
Upvotes: 1
Views: 13778
Reputation: 3080
I think this will work
$DateTime = DateTime::createFromFormat('Y-m-d', $yourOldDateString);
$newDateString = $DateTime->format('d/M/Y');
Upvotes: 0
Reputation: 2258
You can format date like below.
echo Yii::$app->formatter->asDate('2017-03-30', 'd-M-Y'); // 30-Mar-2017
try this.
and you can check Yii2 doc
Upvotes: 1