2

I found no way so far to change the date / time format on the order grid (or even better all grids where its relevant). I guess some XML magic is required here.

Please take a look at https://prnt.sc/pmyywc for details.

Can anyone help here?

Magento 2.2.3

1

You can use class in your column field in your ui_component XML file like below..

In your case, you can override your sales_order_grid.xml in your custom module or custom theme and you can change column class for date.

<column name="date" class="Vendor\Module\Ui\Component\Listing\Column\Date">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="filter" xsi:type="string">text</item>
            <item name="label" xsi:type="string" translate="true">Date</item>
        </item>
    </argument>
</column>

And then you need to create UI component class for it. You can create that on below path..

app/code/Vendor/Module/Ui/Component/Listing/Column/Date.php

Content for this file is ..

<?php
namespace Vendor\Module\Ui\Component\Listing\Column;

use Magento\Ui\Component\Listing\Columns\Column;

class Date extends Column
{
    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items'])) {
            foreach ($dataSource['data']['items'] as & $item) {
                if ($this->getData('name') == 'date') {
                   $item[$this->getData('name')] = date("d.m.Y H:i:s")." Uhr";
                }
            }
        }

        return $dataSource;
    }
}

Output :

enter image description here

Hope this will help you!

| improve this answer | |
  • Is above solution works for you ? – Kishan Savaliya Nov 4 '19 at 12:10
1

You just need to refer https://devdocs.magento.com/guides/v2.4/ui_comp_guide/components/ui-datecolumn.html

And add component="Magento_Ui/js/grid/columns/date" in the column node.

<listing>
...
<columns>
    <column name="date_column_example_1" class="Magento\Ui\Component\Listing\Columns\Date" component="Magento_Ui/js/grid/columns/date">
        <settings>
            <filter>dateRange</filter>
            <dataType>date</dataType>
            <dataType>date</dataType>
            <label translate="true">Date Column Example 1</label>
        </settings>
    </column>
    <column name="date_column_example_2" class="Magento\Ui\Component\Listing\Columns\Date" component="Magento_Ui/js/grid/columns/date">
        <settings>
            <filter>dateRange</filter>
            <dataType>date</dataType>
            <dateFormat>yyyy-MM-dd hh:mm:ss</dateFormat>
            <label translate="true">Date Column Example 2</label>
            <timezone>false</timezone>
        </settings>
    </column>
    ...
</columns>
...
| improve this answer | |
0

copy vendor/magento/module-ui/view/base/web/js/grid/columns/date.js and place it in your theme with module name "Magento_Ui"

change default dateFormat:

return Column.extend({
        defaults: {
            dateFormat: 'dd-mm-YYYY h:mm:ss A'  //Updated for change date formate 
        },

        /**
         * Overrides base method to normalize date format.
         *
         * @returns {DateColumn} Chainable.
         */
        initConfig: function () {
            this._super();

            this.dateFormat = utils.normalizeDate(this.dateFormat);

            return this;
        },

        /**
         * Formats incoming date based on the 'dateFormat' property.
         *
         * @returns {String} Formatted date.
         */
        getLabel: function (value, format) {
            var date = moment(this._super());

            date = date.isValid() && value[this.index] ?
                date.format(format || this.dateFormat) :
                '';

            return date;
        }
    });

Note: you have to place in theme with same path

| improve this answer | |
  • Ronak Chauhan: Sounds easy, but did not work, cleaned cache but the old date format still shows. – Arnie Oct 23 '19 at 10:29
  • clean cache will not work. you have to check pub/static file and if old file code exist at there then please run "bin/magento setup:upgrate" and check again same file, if still exist then run "bin/magento setup:static-content:deploy -f" – Ronak Chauhan Oct 24 '19 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.