cancel
Showing results for 
Search instead for 
Did you mean: 

How to show Time in datepicker in magento 2x backend?

SOLVED

How to show Time in datepicker in magento 2x backend?

Hi Guys, 

I'm using Magento CE 2.2.4 and I wanna add time in datepicker in backend. Especially on Special price section. I want the datepicker to be displayed like this with time (hour and minute selection option)

timepicker.png

 

Can any one help how to show the time?  I'll be grateful to you.

 

TIA

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to show Time in datepicker in magento 2x backend?

Hello @fahmad 

 

sorry for late replay, today i get some time and i checked and i found it is coming from

Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AdvancedPricing.php

 

into bottom of area line 579 around

 $this->meta = $this->arrayManager->merge(
                $pathFrom . '/arguments/data/config',
                $this->meta,
                [
                     'label' => __('Special Price From'),
                    'scopeLabel' => null,
                    'additionalClasses' => 'admin__field-date',
					'options' => ['showsTime'=>true] // add this line to show time
					
                ]
            );

i did not checked save and all thing work. also, you need to create a plugin for add this.

 

Hope it will help you.

 

If help you then mark as a solution

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

View solution in original post

5 REPLIES 5

Re: How to show Time in datepicker in magento 2x backend?

You want to have the declaration of the field similar to the following;

$fieldset->addField(
    'date_to',
    'date',
    [
        'name' => 'date_to',
        'label' => __('Start Time'),
        'title' => __('Start Time'),
        'date_format' => $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT),
        'time_format' => $this->_localeDate->getTimeFormat(\IntlDateFormatter::SHORT),
        'class' => 'validate-date'
    ]
);

The important bits are the date_format and time_format keys.

 

Re: How to show Time in datepicker in magento 2x backend?

Hello @fahmad 

 

sorry for late replay, today i get some time and i checked and i found it is coming from

Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AdvancedPricing.php

 

into bottom of area line 579 around

 $this->meta = $this->arrayManager->merge(
                $pathFrom . '/arguments/data/config',
                $this->meta,
                [
                     'label' => __('Special Price From'),
                    'scopeLabel' => null,
                    'additionalClasses' => 'admin__field-date',
					'options' => ['showsTime'=>true] // add this line to show time
					
                ]
            );

i did not checked save and all thing work. also, you need to create a plugin for add this.

 

Hope it will help you.

 

If help you then mark as a solution

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: How to show Time in datepicker in magento 2x backend?

Thanks a lot @Sunil Patel 
It worked. Even I don't have to create a plugin for this.

Re: How to show Time in datepicker in magento 2x backend?

Hello @fahmad 

 

we can not able to change into core fileSmiley Happy


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: How to show Time in datepicker in magento 2x backend?

I have a way to do this editing more cleanly, without touching the Core Magento file. It's late for this post but I hope it helps someone.

Magento 2.4.5 - 2.4.6

 

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <!-- Plugings -->
    <type name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AdvancedPricing">
        <plugin name="vendor_module_plugin" type="Vendor\Module\Plugin\Ui\DataProvider\Product\Form\Modifier\AdvancedPricingPlugin" sortOrder="1"/>
    </type>
</config>
<?php

namespace Vendor\Module\Plugin\Ui\DataProvider\Product\Form\Modifier;

class AdvancedPricingPlugin
{
    public function afterModifyMeta(
        \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AdvancedPricing $subject,
        $result
    ) {
        $result['advanced_pricing_modal']['children']['advanced-pricing']['children']
        ['container_special_from_date']['children']['special_from_date']['arguments']
        ['data']['config']['options'] = ['showsTime' => true];

        $result['advanced_pricing_modal']['children']['advanced-pricing']['children']
        ['container_special_from_date']['children']['special_to_date']['arguments']
        ['data']['config']['options'] = ['showsTime' => true];

        return $result;
    }
}