Many times you might have faced the problem of date and time in the exported UI admin grid. For instance, you are showing the date and time in IST format in the ui Grid with 12 hours time format and when you export it in the CSV or XML file, it will show the date and time in the format which is storesd in the database. In this article, I will show you the solution for How to export the admin grid in the current timezone.

Export the admin grid in the current timezone

Step 1: Create di.xml file at app/codeVendor/Module/etc/adminhtml and paste the below code. You need to change the code as per your requirements.

<type name="Magento\Ui\Model\Export\MetadataProvider">
    <arguments>
    	<argument name="data" xsi:type="array"> 
    		<item name="sales_order_grid" xsi:type="array">
    			<item name="last_status_changed_date" xsi:type="string">status_last_update</item>
    		</item>
    	</argument>
   </arguments>
</type>

In this blog post, I have added a new column named last_status_changed_date  in the sales order grid. I assume you know how to create a new column in the order grid.

Step 2: Execute the following commands.

php bin/magento setup:di:compile
php bin/magento cache:clean

After you check the grid and export data, you will see the date and time will be shown as per the current timezone.
Here is the admin sales order grid with a custom column named Last Status Changed Date.

Here is the exported data of the above grid:

You can check that the Last Status Update Date column in the exported sheet holds with IST time which is mentioned in the grid column listing.

In this blog post, we explored strategies for changing the format of date and time in the UI component Grid export records.I hope this blog post has provided valuable insights and practical advice. I encourage you to join the conversation in the comments section below.

Thank you for reading.

Rate this post