1

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

2 Answers 2

1

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

Yii2 Formatters

Sign up to request clarification or add additional context in comments.

Comments

0

I think this will work

$DateTime = DateTime::createFromFormat('Y-m-d', $yourOldDateString);
$newDateString = $DateTime->format('d/M/Y');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.