We use cookies to make your experience better. To comply with the new e-Privacy directive, we need to ask for your consent to set the cookies. Learn more.
Magento 2: Add DatePicker in System Config
To add a Date Picker in Magento 2 System Configuration, follow these steps:
1. Create Block
Create aDatePicker.php file in app/code/Vendor/Module/Block/:
<?php
namespace Vendor\Module\Block\Adminhtml;
class Date extends \Magento\Config\Block\System\Config\Form\Field
{
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
$element->setDateFormat(\Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT);
$element->setTimeFormat("HH:mm:ss"); //set date and time as per your need
return parent::render($element);
}
}
2. Create System.xml
Add the below code to yoursystem.xml file
<field id="customdate" translate="label" type="date" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Customized Date Field</label>
<frontend_model>Vendor\Module\Block\Adminhtml\DatePicker</frontend_model>
</field>