DetailView Date format problem

I am using INT fields in my db to store timestamp values


[['birth_date'], 'date',

                'format' => 'mm/dd/yyy',

                'timestampAttribute' => 'birth_date'

            ],

I also use the timestamp Behaviour.

When I load the form (actionUpdate) the date is correct.

In the ‘view’ I use


/* The date format is 'mm/dd/yyyy' */

    <?=

    DetailView::widget([

        'model' => $model,

        'attributes' => [

            ...

            'birth_date:date', // = time() for 06/23/####

            'hire_date:date',  // = time() for 09/01/2004

             ...

            'created_at:datetime', // = time() for 07/19/2017

            'updated_at:datetime', // = time() for 07/21/2017

        ],

    ])

    ?>



The display shows the correct day and year, but the month only showing Jul. I just noticed this so I don’t know if it is showing the current month, or something else.

Thank You

I have the same problem on two different development machines. When I first posted this, it was on a machine that was using the php internal server. the second machine is running XAMPP Apache.

I have set


'timezone' =>'America/Chicago',

in the config files.

UPDATE: Today I looked at my Profile view, and the dates still showed the ‘Jul’ dates. However: I went in to the update, re-entered the dates, saved, and the now show ‘Aug’.

What Gives?

I guess no one understands timestamp validation :(

I feel for you, I fought with date filtering in gridview all day.

Try this…




           //'created_at',

	   ['attribute'=>'created_at',

	     'value' => function ($model) {

              return Yii::$app->formatter->asDateTime($model->created_at, 'php:m/d/Y');

	      },

	    ],



I guess setting the dateFormat will solve your problem:


<?=

    DetailView::widget([

        'model' => $model,


        'formatter' => [

            'class' => '\yii\i18n\Formatter',

            'dateFormat' => 'MM/dd/yyyy',

            'datetimeFormat' => 'MM/dd/yyyy HH:mm::ss',

        ],




        'attributes' => [

            ...

            'birth_date:date', // = time() for 06/23/####

            'hire_date:date',  // = time() for 09/01/2004

             ...

            'created_at:datetime', // = time() for 07/19/2017

            'updated_at:datetime', // = time() for 07/21/2017

        ],

    ])

?>

1 Like