0

how can i change Expire Date format from mm/dd/yy to dd/mm/yy in product form admin panel

enter image description here

2
  • @khaled is Expire Date is custom product attribute?? Commented Nov 3, 2023 at 12:06
  • Can you please share your custom attribute name or code?
    – Msquare
    Commented Nov 3, 2023 at 14:55

1 Answer 1

0

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;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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