cancel
Showing results for 
Search instead for 
Did you mean: 

How can I change the date format on order grid

How can I change the date format on order grid

I want to change the purchase date format in the order information grid to match the image. Even if I change the locale setting to my country, it remains the same. How can I change it?

 

stackover.png

1 REPLY 1

Re: How can I change the date format on order grid

Hello @nixordaumnaea1 

 

To change the date format on the order grid in Magento 2, you'll need to create a custom module and modify the existing code. Here are the general steps you can follow:

  • Create a custom module: Create a custom module in your Magento 2 instance. If you're unfamiliar with module creation, you can refer to the official Magento 2 documentation for detailed instructions.
  • Override the order grid block: In your custom module, you need to override the order grid block to modify the date format. Create a new file app/code/YourNamespace/YourModule/Block/Adminhtml/Sales/Order/Grid.php and extend the core grid block Magento\Backend\Block\Widget\Grid.
    <?php
    namespace YourNamespace\YourModule\Block\Adminhtml\Sales\Order;
    use Magento\Backend\Block\Widget\Grid as WidgetGrid;
    class Grid extends WidgetGrid
    {
        protected function _prepareColumns()
        {
            $this->addColumn(
                'created_at',
                [
                    'header' => __('Created At'),
                    'index' => 'created_at',
                    'type' => 'datetime',
                    'format' => 'd-M-Y', // Specify your desired date format here
                ]
            );
            parent::_prepareColumns();
        }
    }
  • In the code above, we're modifying the created_at column to use the desired date format. Adjust the format value according to your requirements.
  • Register the block in di.xml: To ensure your custom block is used instead of the default block, create or modify the di.xml file located at app/code/YourNamespace/YourModule/etc/adminhtml/di.xml and add the following code:
    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <preference for="Magento\Sales\Block\Adminhtml\Order\Grid" type="YourNamespace\YourModule\Block\Adminhtml\Sales\Order\Grid" />
    </config>
  • Enable the module and clear cache: Enable your custom module by running the following command in the Magento root directory:
    • php bin/magento module:enable YourNamespace_YourModule
  • Then, clear the Magento cache using:

    •  

      php bin/magento cache:clean

  • After completing these steps, the date format for the created_at column in the order grid should be updated according to the format specified in your custom block.

If you find our reply helpful, please give us kudos.

 

A Leading Magento Development Agency That Delivers Powerful Results, Innovation, and Secure Digital Transformation.

 

WebDesk Solution Support Team

Get a Free Quote | | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789

Thank You,


WebDesk Solution Support Team
Get a Free Quote | Email | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789


Location: 150 King St. W. Toronto, ON M5H 1J9