{"id":18907,"date":"2025-07-22T12:38:23","date_gmt":"2025-07-22T07:08:23","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/?p=18907"},"modified":"2025-07-22T12:38:24","modified_gmt":"2025-07-22T07:08:24","slug":"magento-2-add-date-time-picker-in-admin-system-configuration","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/magento-2-add-date-time-picker-in-admin-system-configuration\/","title":{"rendered":"Magento 2 Add Date &amp; Time Picker in Admin System Configuration: Steps"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">By default, Magento provides a date and time picker in certain areas such as Cart Price Rules and Catalog Price Rules, allowing users to set \u201cFrom\u201d and \u201cTo\u201d dates.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, Magento does not offer a built-in date and time picker UI for system configuration via system.xml.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Therefore, when there is a requirement to select dates or time ranges in the admin panel, custom code must be implemented to enable this functionality.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">While developing custom features for Magento store owners, it\u2019s common to require date and time input from the admin for specific business logic.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, a custom module might need to capture periods for license expiry, promotional rule duration, or a discount\u2019s active time frame.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1274\" height=\"798\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/07\/Date-Time-Picker.png\" alt=\"Date Time Picker\" class=\"wp-image-18909\" srcset=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/07\/Date-Time-Picker.png 1274w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/07\/Date-Time-Picker-250x157.png 250w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/07\/Date-Time-Picker-700x438.png 700w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/07\/Date-Time-Picker-768x481.png 768w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/07\/Date-Time-Picker-403x252.png 403w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/07\/Date-Time-Picker-964x604.png 964w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/07\/Date-Time-Picker-120x75.png 120w\" sizes=\"auto, (max-width: 1274px) 100vw, 1274px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">In such cases, the solution provided here will help you integrate a date and time picker in the Magento 2 admin system configuration.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Magento 2 add Date &amp; Time Picker in admin system Configuration<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1:<\/strong> Add Code in The system.xml File&nbsp;<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use the below code at your existing module&#8217;s <strong>sytem.xml<\/strong> file. It would be like <strong>app\\code[Vendor][Module]\\etc\\adminhtml\\system.xml<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;field id=\"dateIdName\" translate=\"label comment\" sortOrder=\"10\" type=\"date\" showInDefault=\"1\" showInStore=\"1\" >\n&lt;label>Date Time Picker&lt;\/label>\n&lt;frontend_model>Vendor\\Module\\Block\\System\\Config\\DatePicker&lt;\/frontend_model>\n&lt;\/field>\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Create DatePicker.php File<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now, create the <strong>DatePicker.php<\/strong> file at the location app\\code[Vendor][Module]\\Block\\System\\Config<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Vendor\\Module\\Block\\System\\Config;\n\nuse Magento\\Framework\\Registry;\nuse Magento\\Backend\\Block\\Template\\Context;\n\nclass DatePicker extends \\Magento\\Config\\Block\\System\\Config\\Form\\Field\n{\nprotected $_coreRegistry;\n\npublic function __construct(\nContext $context,\nRegistry $coreRegistry,\narray $data = []\n){\n$this->_coreRegistry = $coreRegistry;\nparent::__construct($context, $data);\n}\n\npublic function render(\\Magento\\Framework\\Data\\Form\\Element\\AbstractElement $element)\n{\n\/\/ for only date option\n$element->setDateFormat(\\Magento\\Framework\\Stdlib\\DateTime::DATE_INTERNAL_FORMAT);\n\n\/\/ For Date &amp; time option\n\/\/ $element->setDateFormat(\\Magento\\Framework\\Stdlib\\DateTime::DATETIME_INTERNAL_FORMAT);\n\n\/\/$element->setDateFormat(\"dd-mm-Y\");\n\n\/\/ For set max date or disabled future date\n$element->setMaxDate(date('Y-m-d'));\n\n\/\/ For set Min date or disabled previous date\n$element->setMaxDate('2022-04-01');\nreturn parent::render($element);\n}\n}\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then, you will be able to view the date and time picker to streamline your Magento backend tasks with our custom solutions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you\u2019re looking to build tailored features or need custom extension development for your store, feel free to<a href=\"https:\/\/meetanshi.com\/magento-development-services.html\"> get in touch<\/a> \u2014 we\u2019re here to bring your ideas to life. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>By default, Magento provides a date and time picker in certain areas such as Cart Price Rules and Catalog Price Rules, allowing users to set&#8230;<\/p>\n","protected":false},"author":5,"featured_media":18918,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-18907","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/18907","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=18907"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/18907\/revisions"}],"predecessor-version":[{"id":18921,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/18907\/revisions\/18921"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media\/18918"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=18907"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=18907"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=18907"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}