how can i change Expire Date format from mm/dd/yy to dd/mm/yy in product form admin panel
1 Answer
Please add the below files to your module.
app/code/VendorName/ModuleName/etc/adminhtml
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool">
<arguments>
<argument name="modifiers" xsi:type="array">
<item name="custom_date" xsi:type="array">
<item name="class" xsi:type="string">VendorName\ModuleName\Ui\DataProvider\Product\Form\Modifier\Datetime</item>
<item name="sortOrder" xsi:type="number">100</item>
</item>
</argument>
</arguments>
</virtualType>
</config>
app/code/VendorName/ModuleName/Ui/DataProvider/Product/Form/Modifier
Datetime.php
<?php
namespace VendorName\ModuleName\Ui\DataProvider\Product\Form\Modifier;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Framework\Stdlib\ArrayManager;
class Datetime extends AbstractModifier
{
protected $arrayManager;
public function __construct(
ArrayManager $arrayManager
) {
$this->arrayManager = $arrayManager;
}
/**
* {@inheritdoc}
*/
public function modifyMeta(array $meta)
{
$meta = $this->updatetimeFormate($meta);
return $meta;
}
/**
* {@inheritdoc}
*/
public function modifyData(array $data)
{
return $data;
}
protected function updatetimeFormate(array $meta)
{
$fieldCode = 'Your_custom_attribute_name'; // add your attribute name here
$elementPath = $this->arrayManager->findPath($fieldCode, $meta, null, 'children');
$containerPath = $this->arrayManager->findPath(static::CONTAINER_PREFIX . $fieldCode, $meta, null, 'children');
if (!$elementPath) {
return $meta;
}
$meta = $this->arrayManager->merge(
$containerPath,
$meta,
[
'children' => [
$fieldCode => [
'arguments' => [
'data' => [
'config' => [
'default' => '',
'options' => [
'dateFormat' > 'dd-MM-yyyy',
'timeFormat' => 'HH:mm:ss',
'showsTime' => true
]
],
],
],
]
]
]
);
return $meta;
}
}