I need an example function to change the date to the Brazilian standard.
I need an example function to change the date to the Brazilian standard.
You can use the following function:
Yii::$app->getFormatter()->asDate($variavel_para_formatacao)
Do not forget to make the necessary settings in the common / config / main.cfg
'components' => [
//...
'formatter' => [
'dateFormat' => 'dd/MM/yyyy',
'datetimeFormat' => 'dd/MM/yyy H:i',
'timeFormat' => 'H:i',
'decimalSeparator' => ',',
'thousandSeparator' => '.',
'currencyCode' => 'R$',
],
//....
Try to use the native function to own PHP:
$mode->sua_data = date('d-m-Y', strtotime($model->sua_data));
date
// Format a date for other formats
strtotime
// Transforms a String into dateTime
Your date (probably removed from the database) will come as a normal string, so before using the date it is necessary to make it into dateTime. If a normal String is passed to the date it will transform it into a deault date (01-01-1970).