How to implement Time Range Picker in Magento 2 Admin system.xml? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Date field system.xmlMagento 2 - time picker on backend (xml form)How to overwrite System.xml?Magento 2 Pattern Library — Date & Time SelectorsHTTP 500 Error in System ConfigurationMagento 2 - time picker on backend (xml form)Magento 2 Add Datetime picker in system.xmlDate Time picker and time zone woesHow to implement Single Date and Time Picker in Magento 2Custom Module for Custom Column using Plugin Yes/No optionMagento 2 DateTime picker - Limit time selection rangeMagento2 UI Component admin Grid / Listing stuck loading

My body leaves; my core can stay

ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?

Example of compact Riemannian manifold with only one geodesic.

Presidential Pardon

What is the padding with red substance inside of steak packaging?

Intergalactic human space ship encounters another ship, character gets shunted off beyond known universe, reality starts collapsing

How to read αἱμύλιος or when to aspirate

What do I do when my TA workload is more than expected?

US Healthcare consultation for visitors

Can withdrawing asylum be illegal?

Variable with quotation marks "$()"

Match Roman Numerals

Do warforged have souls?

Do ℕ, mathbbN, BbbN, symbbN effectively differ, and is there a "canonical" specification of the naturals?

Working through the single responsibility principle (SRP) in Python when calls are expensive

Does Parliament hold absolute power in the UK?

"is" operation returns false even though two objects have same id

Single author papers against my advisor's will?

Am I ethically obligated to go into work on an off day if the reason is sudden?

Does Parliament need to approve the new Brexit delay to 31 October 2019?

should truth entail possible truth

What can I do if neighbor is blocking my solar panels intentionally?

Was credit for the black hole image misappropriated?

One-dimensional Japanese puzzle



How to implement Time Range Picker in Magento 2 Admin system.xml?



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Date field system.xmlMagento 2 - time picker on backend (xml form)How to overwrite System.xml?Magento 2 Pattern Library — Date & Time SelectorsHTTP 500 Error in System ConfigurationMagento 2 - time picker on backend (xml form)Magento 2 Add Datetime picker in system.xmlDate Time picker and time zone woesHow to implement Single Date and Time Picker in Magento 2Custom Module for Custom Column using Plugin Yes/No optionMagento 2 DateTime picker - Limit time selection rangeMagento2 UI Component admin Grid / Listing stuck loading



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I found one similar solution that almost does what I want.
DateTimePicker System.xml



I have implemented its code and was able to display a DateTime Picker in my admin configuration. However, I would like to implement a Time Range Picker but I don't need a UI component way of implementing it.










share|improve this question






























    1















    I found one similar solution that almost does what I want.
    DateTimePicker System.xml



    I have implemented its code and was able to display a DateTime Picker in my admin configuration. However, I would like to implement a Time Range Picker but I don't need a UI component way of implementing it.










    share|improve this question


























      1












      1








      1


      1






      I found one similar solution that almost does what I want.
      DateTimePicker System.xml



      I have implemented its code and was able to display a DateTime Picker in my admin configuration. However, I would like to implement a Time Range Picker but I don't need a UI component way of implementing it.










      share|improve this question
















      I found one similar solution that almost does what I want.
      DateTimePicker System.xml



      I have implemented its code and was able to display a DateTime Picker in my admin configuration. However, I would like to implement a Time Range Picker but I don't need a UI component way of implementing it.







      magento2.3 system.xml datepicker timepicker






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 27 mins ago







      magefms

















      asked 2 days ago









      magefmsmagefms

      2,6342528




      2,6342528




















          3 Answers
          3






          active

          oldest

          votes


















          1














          If you wish to add time from/to elements as a slider, you can customize an element frontend model and add your own template.



          How it will be looking



          Here is my example (ported from the regular form to the store configuration section):



          Field in the system.xml:



          <field id="delivery_time" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
          <label>Delivery Time</label>
          <frontend_model>MageWorxExampleConfigModelConfigFrontendModelDeliveryTime</frontend_model>
          </field>


          Note: real values will be stored with the delivery_time_from and delivery_time_to indexes.



          Frontend model, where I have replaced the default output of the element:



          <?php

          namespace MageWorxExampleConfigModelConfigFrontendModel;


          class DeliveryTime extends MagentoConfigBlockSystemConfigFormField

          /**
          * Retrieve element HTML markup
          *
          * @param MagentoFrameworkDataFormElementAbstractElement $element
          * @return string
          * @throws MagentoFrameworkExceptionLocalizedException
          */
          protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element)

          $renderer = $this->getLayout()->createBlock(
          'MageWorxExampleConfigBlockTimeSlider'
          );
          $renderer->setElement($element);

          return $renderer->toHtml();




          here we just using a block MageWorxExampleConfigBlockTimeSlider instead of general render.



          And here is the block with template (where slider was defined):



          <?php

          namespace MageWorxExampleConfigBlock;

          use MagentoFrameworkDataFormElementAbstractElement;

          /**
          * Class TimeSlider
          */
          class TimeSlider extends MagentoFrameworkViewElementTemplate implements
          MagentoFrameworkDataFormElementRendererRendererInterface,
          MagentoWidgetBlockBlockInterface


          const TIME_NAME_FROM = 'groups[main][fields][delivery_time_from][value]';
          const TIME_NAME_TO = 'groups[main][fields][delivery_time_to][value]';

          /**
          * Form element which re-rendering
          *
          * @var MagentoFrameworkDataFormElementFieldset
          */
          protected $element;

          /**
          * @var string
          */
          protected $_template = 'MageWorx_ExampleConfig::form/renderer/timeslider.phtml';

          /**
          * @var string
          */
          protected $_htmlId = 'time-range';

          /**
          * Retrieve an element
          *
          * @return MagentoFrameworkDataFormElementFieldset
          */
          public function getElement()

          return $this->element;


          /**
          * Set an element
          *
          * @param AbstractElement $element
          * @return $this
          */
          public function setElement(MagentoFrameworkDataFormElementAbstractElement $element)

          $this->element = $element;

          return $this;


          /**
          * Render element
          *
          * @param AbstractElement $element
          * @return string
          */
          public function render(AbstractElement $element)

          $this->element = $element;

          return $this->toHtml();


          /**
          * @return string
          */
          public function getHtmlId()

          return $this->_htmlId;


          /**
          * @return string
          */
          public function getNameFrom()

          return self::TIME_NAME_FROM;


          /**
          * @return string
          */
          public function getNameTo()

          return self::TIME_NAME_TO;


          /**
          * @param int $minutes
          * @return string
          */
          public function minutesToTime($minutes)

          $hours = floor($minutes / 60);
          $minutes = $minutes % 60;
          $part = $hours >= 12 ? 'PM' : 'AM';

          return sprintf('%02d:%02d %s', $hours, $minutes, $part);


          /**
          * @return string
          * @throws MagentoFrameworkExceptionValidatorException
          */
          protected function _toHtml()

          if (!$this->getTemplate())
          return '';


          return $this->fetchView($this->getTemplateFile());




          Note: you should change values of the constants TIME_NAME_FROM and TIME_NAME_TO to own ones, according your definition in the system.xml.



          Template:



          <?php

          /** @var MageWorxExampleConfigBlockTimeSlider $block */
          $element = $block->getElement();
          $form = $element->getForm();
          /** @var MagentoConfigBlockSystemConfigForm $parentForm */
          $parentForm = $form->getParent();
          $timeFrom = $parentForm->getConfigValue('example_config/main/delivery_time_from');;
          $timeTo = $parentForm->getConfigValue('example_config/main/delivery_time_to');;
          ?>
          <div id="time-range" class="field field-time_range">
          <label class="label" style="white-space: normal;">
          <?php echo __('Time Range: ');?>
          <span class="slider-time">
          <?php echo $block->minutesToTime($timeFrom);?>
          </span>
          <?php echo ' - '; ?>
          <span class="slider-time2">
          <?php echo $block->minutesToTime($timeTo);?>
          </span>
          </label>
          <div class="sliders_step1 control">
          <div id="slider-range"></div>
          <input type="hidden"
          name="<?php echo $block->getNameFrom();?>"
          value="<?php echo $timeFrom?>""
          />
          <input type="hidden"
          name="<?php echo $block->getNameTo();?>"
          value="<?php echo $timeTo?>""
          />
          </div>
          </div>
          <script type="text/javascript">
          require(['jquery', 'jquery/ui'], function($)
          $("#slider-range").slider(
          range: true,
          min: 0,
          max: 1440,
          step: 15,
          values: [<?php echo $timeFrom?>, <?php echo $timeTo?>],
          slide: function (e, ui)
          var hours1 = Math.floor(ui.values[0] / 60);
          var minutes1 = ui.values[0] - (hours1 * 60);

          if (hours1.length == 1) hours1 = '0' + hours1;
          if (minutes1.length == 1) minutes1 = '0' + minutes1;
          if (minutes1 == 0) minutes1 = '00';
          if (hours1 >= 12)
          if (hours1 == 12)
          hours1 = hours1;
          minutes1 = minutes1 + " PM";
          else
          hours1 = hours1 - 12;
          minutes1 = minutes1 + " PM";

          else
          hours1 = hours1;
          minutes1 = minutes1 + " AM";

          if (hours1 == 0)
          hours1 = 12;
          minutes1 = minutes1;



          $('.slider-time').html(hours1 + ':' + minutes1);

          var hours2 = Math.floor(ui.values[1] / 60);
          var minutes2 = ui.values[1] - (hours2 * 60);

          if (hours2.length == 1) hours2 = '0' + hours2;
          if (minutes2.length == 1) minutes2 = '0' + minutes2;
          if (minutes2 == 0) minutes2 = '00';
          if (hours2 >= 12)
          if (hours2 == 12)
          hours2 = hours2;
          minutes2 = minutes2 + " PM";
          else if (hours2 == 24)
          hours2 = 11;
          minutes2 = "59 PM";
          else
          hours2 = hours2 - 12;
          minutes2 = minutes2 + " PM";

          else
          hours2 = hours2;
          minutes2 = minutes2 + " AM";


          $('.slider-time2').html(hours2 + ':' + minutes2);
          $('[name="<?php echo $block->getNameFrom();?>"]').val(ui.values[0]);
          $('[name="<?php echo $block->getNameTo();?>"]').val(ui.values[1]);

          );
          );
          </script>


          That's all. Based on this example you can modify code to add base features like a use global value etc.



          Here is full code on the GitHub.



          PS: Example partially taken from the Shipping Suite Ultimate Extension by MageWorx (where that kind of slider used in the form).



          PPS: in the example time stored in the database in minutes, like 120 => 2:00 AM.






          share|improve this answer






























            2














            I would suggest to use the same way magento uses for saving time.



            In your admin panel, goto




            Stores -> Configuration -> Advanced -> System -> Scheduled Backup Settings




            See the Start Time field.



            enter image description here



            You may use the same thing in your system.xml file. It seems more accurate.



            Let me know if you need a code sample for that. I have used the same in one of my module.





            etc/adminhtml/system.xml





            <field id="opening_time" translate="label" type="time" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="40">
            <label>Opening Time</label>
            </field>


            Just add above field in system.xml and it will work as per magento standard. It will save time like 15,25,00. The type='time' makes it work. Thats it. No additional coding is needed.






            share|improve this answer

























            • can you include code for this one so that I can check

              – magefms
              2 days ago











            • Edited answer with the code. Please check.

              – Yash Shah
              2 days ago











            • okay, I will update you if it works

              – magefms
              2 days ago


















            1














            You can follow steps below to show Datetime field in your custom module admin config section



            step 1) Create system.xml under ***app/code/Vendor/Module/etc/adminFile:*



            File : app/code/Vendor/MyModule/etc/adminhtml/system.xml



            <?xml version="1.0"?>

            <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
            <system>
            <tab id="mycustom" translate="label" sortOrder="450">
            <label>My Custom Setting</label>
            </tab>
            <section id="mycustom" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
            <class>separator-top</class>
            <label>My Custom Setting</label>
            <tab>mycustom</tab>
            <resource>Magento_Checkout::config</resource>
            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
            <field id="mydate" translate="label" type="date" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>My Date Field</label>
            <frontend_model>VendorMyModuleBlockAdminhtmlSystemConfigDateTime</frontend_model>
            </field>
            </group>
            </section>
            </system>
            </config>


            step 2) Create the block DateTime.php under /app/code/Vendor/MyModule/Block/Adminhtml/System/Config/DateTime.php



            File : /app/code/Vendor/MyModule/Block/Adminhtml/System/Config/DateTime.php



            <?php

            namespace VendorMyModuleBlockAdminhtmlSystemConfig;

            class DateTime extends MagentoConfigBlockSystemConfigFormField


            protected $timezone;

            public function __construct(
            MagentoBackendBlockTemplateContext $context,
            MagentoFrameworkStdlibDateTimeTimezoneInterface $timezone,
            array $data = []
            )
            $this->timezone = $timezone;
            parent::__construct($context, $data);


            public function render(MagentoFrameworkDataFormElementAbstractElement $element)

            $element->setDateFormat($this->timezone->getDateFormat());
            $element->setTimeFormat($this->timezone->getTimeFormat());
            $element->setShowsTime(true);
            return parent::render($element);




            step 3: Run Following commands



            sudo php bin/magento setup:di:compile
            sudo php bin/magento cache:flush


            step 4: Check your custom module admin config section for newly added datetime config field.



            enter image description here






            share|improve this answer























            • Thanks for the answer bro, but I have done that already, please review my requirement, I need time picker only.

              – magefms
              2 days ago











            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f269454%2fhow-to-implement-time-range-picker-in-magento-2-admin-system-xml%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            If you wish to add time from/to elements as a slider, you can customize an element frontend model and add your own template.



            How it will be looking



            Here is my example (ported from the regular form to the store configuration section):



            Field in the system.xml:



            <field id="delivery_time" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
            <label>Delivery Time</label>
            <frontend_model>MageWorxExampleConfigModelConfigFrontendModelDeliveryTime</frontend_model>
            </field>


            Note: real values will be stored with the delivery_time_from and delivery_time_to indexes.



            Frontend model, where I have replaced the default output of the element:



            <?php

            namespace MageWorxExampleConfigModelConfigFrontendModel;


            class DeliveryTime extends MagentoConfigBlockSystemConfigFormField

            /**
            * Retrieve element HTML markup
            *
            * @param MagentoFrameworkDataFormElementAbstractElement $element
            * @return string
            * @throws MagentoFrameworkExceptionLocalizedException
            */
            protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element)

            $renderer = $this->getLayout()->createBlock(
            'MageWorxExampleConfigBlockTimeSlider'
            );
            $renderer->setElement($element);

            return $renderer->toHtml();




            here we just using a block MageWorxExampleConfigBlockTimeSlider instead of general render.



            And here is the block with template (where slider was defined):



            <?php

            namespace MageWorxExampleConfigBlock;

            use MagentoFrameworkDataFormElementAbstractElement;

            /**
            * Class TimeSlider
            */
            class TimeSlider extends MagentoFrameworkViewElementTemplate implements
            MagentoFrameworkDataFormElementRendererRendererInterface,
            MagentoWidgetBlockBlockInterface


            const TIME_NAME_FROM = 'groups[main][fields][delivery_time_from][value]';
            const TIME_NAME_TO = 'groups[main][fields][delivery_time_to][value]';

            /**
            * Form element which re-rendering
            *
            * @var MagentoFrameworkDataFormElementFieldset
            */
            protected $element;

            /**
            * @var string
            */
            protected $_template = 'MageWorx_ExampleConfig::form/renderer/timeslider.phtml';

            /**
            * @var string
            */
            protected $_htmlId = 'time-range';

            /**
            * Retrieve an element
            *
            * @return MagentoFrameworkDataFormElementFieldset
            */
            public function getElement()

            return $this->element;


            /**
            * Set an element
            *
            * @param AbstractElement $element
            * @return $this
            */
            public function setElement(MagentoFrameworkDataFormElementAbstractElement $element)

            $this->element = $element;

            return $this;


            /**
            * Render element
            *
            * @param AbstractElement $element
            * @return string
            */
            public function render(AbstractElement $element)

            $this->element = $element;

            return $this->toHtml();


            /**
            * @return string
            */
            public function getHtmlId()

            return $this->_htmlId;


            /**
            * @return string
            */
            public function getNameFrom()

            return self::TIME_NAME_FROM;


            /**
            * @return string
            */
            public function getNameTo()

            return self::TIME_NAME_TO;


            /**
            * @param int $minutes
            * @return string
            */
            public function minutesToTime($minutes)

            $hours = floor($minutes / 60);
            $minutes = $minutes % 60;
            $part = $hours >= 12 ? 'PM' : 'AM';

            return sprintf('%02d:%02d %s', $hours, $minutes, $part);


            /**
            * @return string
            * @throws MagentoFrameworkExceptionValidatorException
            */
            protected function _toHtml()

            if (!$this->getTemplate())
            return '';


            return $this->fetchView($this->getTemplateFile());




            Note: you should change values of the constants TIME_NAME_FROM and TIME_NAME_TO to own ones, according your definition in the system.xml.



            Template:



            <?php

            /** @var MageWorxExampleConfigBlockTimeSlider $block */
            $element = $block->getElement();
            $form = $element->getForm();
            /** @var MagentoConfigBlockSystemConfigForm $parentForm */
            $parentForm = $form->getParent();
            $timeFrom = $parentForm->getConfigValue('example_config/main/delivery_time_from');;
            $timeTo = $parentForm->getConfigValue('example_config/main/delivery_time_to');;
            ?>
            <div id="time-range" class="field field-time_range">
            <label class="label" style="white-space: normal;">
            <?php echo __('Time Range: ');?>
            <span class="slider-time">
            <?php echo $block->minutesToTime($timeFrom);?>
            </span>
            <?php echo ' - '; ?>
            <span class="slider-time2">
            <?php echo $block->minutesToTime($timeTo);?>
            </span>
            </label>
            <div class="sliders_step1 control">
            <div id="slider-range"></div>
            <input type="hidden"
            name="<?php echo $block->getNameFrom();?>"
            value="<?php echo $timeFrom?>""
            />
            <input type="hidden"
            name="<?php echo $block->getNameTo();?>"
            value="<?php echo $timeTo?>""
            />
            </div>
            </div>
            <script type="text/javascript">
            require(['jquery', 'jquery/ui'], function($)
            $("#slider-range").slider(
            range: true,
            min: 0,
            max: 1440,
            step: 15,
            values: [<?php echo $timeFrom?>, <?php echo $timeTo?>],
            slide: function (e, ui)
            var hours1 = Math.floor(ui.values[0] / 60);
            var minutes1 = ui.values[0] - (hours1 * 60);

            if (hours1.length == 1) hours1 = '0' + hours1;
            if (minutes1.length == 1) minutes1 = '0' + minutes1;
            if (minutes1 == 0) minutes1 = '00';
            if (hours1 >= 12)
            if (hours1 == 12)
            hours1 = hours1;
            minutes1 = minutes1 + " PM";
            else
            hours1 = hours1 - 12;
            minutes1 = minutes1 + " PM";

            else
            hours1 = hours1;
            minutes1 = minutes1 + " AM";

            if (hours1 == 0)
            hours1 = 12;
            minutes1 = minutes1;



            $('.slider-time').html(hours1 + ':' + minutes1);

            var hours2 = Math.floor(ui.values[1] / 60);
            var minutes2 = ui.values[1] - (hours2 * 60);

            if (hours2.length == 1) hours2 = '0' + hours2;
            if (minutes2.length == 1) minutes2 = '0' + minutes2;
            if (minutes2 == 0) minutes2 = '00';
            if (hours2 >= 12)
            if (hours2 == 12)
            hours2 = hours2;
            minutes2 = minutes2 + " PM";
            else if (hours2 == 24)
            hours2 = 11;
            minutes2 = "59 PM";
            else
            hours2 = hours2 - 12;
            minutes2 = minutes2 + " PM";

            else
            hours2 = hours2;
            minutes2 = minutes2 + " AM";


            $('.slider-time2').html(hours2 + ':' + minutes2);
            $('[name="<?php echo $block->getNameFrom();?>"]').val(ui.values[0]);
            $('[name="<?php echo $block->getNameTo();?>"]').val(ui.values[1]);

            );
            );
            </script>


            That's all. Based on this example you can modify code to add base features like a use global value etc.



            Here is full code on the GitHub.



            PS: Example partially taken from the Shipping Suite Ultimate Extension by MageWorx (where that kind of slider used in the form).



            PPS: in the example time stored in the database in minutes, like 120 => 2:00 AM.






            share|improve this answer



























              1














              If you wish to add time from/to elements as a slider, you can customize an element frontend model and add your own template.



              How it will be looking



              Here is my example (ported from the regular form to the store configuration section):



              Field in the system.xml:



              <field id="delivery_time" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
              <label>Delivery Time</label>
              <frontend_model>MageWorxExampleConfigModelConfigFrontendModelDeliveryTime</frontend_model>
              </field>


              Note: real values will be stored with the delivery_time_from and delivery_time_to indexes.



              Frontend model, where I have replaced the default output of the element:



              <?php

              namespace MageWorxExampleConfigModelConfigFrontendModel;


              class DeliveryTime extends MagentoConfigBlockSystemConfigFormField

              /**
              * Retrieve element HTML markup
              *
              * @param MagentoFrameworkDataFormElementAbstractElement $element
              * @return string
              * @throws MagentoFrameworkExceptionLocalizedException
              */
              protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element)

              $renderer = $this->getLayout()->createBlock(
              'MageWorxExampleConfigBlockTimeSlider'
              );
              $renderer->setElement($element);

              return $renderer->toHtml();




              here we just using a block MageWorxExampleConfigBlockTimeSlider instead of general render.



              And here is the block with template (where slider was defined):



              <?php

              namespace MageWorxExampleConfigBlock;

              use MagentoFrameworkDataFormElementAbstractElement;

              /**
              * Class TimeSlider
              */
              class TimeSlider extends MagentoFrameworkViewElementTemplate implements
              MagentoFrameworkDataFormElementRendererRendererInterface,
              MagentoWidgetBlockBlockInterface


              const TIME_NAME_FROM = 'groups[main][fields][delivery_time_from][value]';
              const TIME_NAME_TO = 'groups[main][fields][delivery_time_to][value]';

              /**
              * Form element which re-rendering
              *
              * @var MagentoFrameworkDataFormElementFieldset
              */
              protected $element;

              /**
              * @var string
              */
              protected $_template = 'MageWorx_ExampleConfig::form/renderer/timeslider.phtml';

              /**
              * @var string
              */
              protected $_htmlId = 'time-range';

              /**
              * Retrieve an element
              *
              * @return MagentoFrameworkDataFormElementFieldset
              */
              public function getElement()

              return $this->element;


              /**
              * Set an element
              *
              * @param AbstractElement $element
              * @return $this
              */
              public function setElement(MagentoFrameworkDataFormElementAbstractElement $element)

              $this->element = $element;

              return $this;


              /**
              * Render element
              *
              * @param AbstractElement $element
              * @return string
              */
              public function render(AbstractElement $element)

              $this->element = $element;

              return $this->toHtml();


              /**
              * @return string
              */
              public function getHtmlId()

              return $this->_htmlId;


              /**
              * @return string
              */
              public function getNameFrom()

              return self::TIME_NAME_FROM;


              /**
              * @return string
              */
              public function getNameTo()

              return self::TIME_NAME_TO;


              /**
              * @param int $minutes
              * @return string
              */
              public function minutesToTime($minutes)

              $hours = floor($minutes / 60);
              $minutes = $minutes % 60;
              $part = $hours >= 12 ? 'PM' : 'AM';

              return sprintf('%02d:%02d %s', $hours, $minutes, $part);


              /**
              * @return string
              * @throws MagentoFrameworkExceptionValidatorException
              */
              protected function _toHtml()

              if (!$this->getTemplate())
              return '';


              return $this->fetchView($this->getTemplateFile());




              Note: you should change values of the constants TIME_NAME_FROM and TIME_NAME_TO to own ones, according your definition in the system.xml.



              Template:



              <?php

              /** @var MageWorxExampleConfigBlockTimeSlider $block */
              $element = $block->getElement();
              $form = $element->getForm();
              /** @var MagentoConfigBlockSystemConfigForm $parentForm */
              $parentForm = $form->getParent();
              $timeFrom = $parentForm->getConfigValue('example_config/main/delivery_time_from');;
              $timeTo = $parentForm->getConfigValue('example_config/main/delivery_time_to');;
              ?>
              <div id="time-range" class="field field-time_range">
              <label class="label" style="white-space: normal;">
              <?php echo __('Time Range: ');?>
              <span class="slider-time">
              <?php echo $block->minutesToTime($timeFrom);?>
              </span>
              <?php echo ' - '; ?>
              <span class="slider-time2">
              <?php echo $block->minutesToTime($timeTo);?>
              </span>
              </label>
              <div class="sliders_step1 control">
              <div id="slider-range"></div>
              <input type="hidden"
              name="<?php echo $block->getNameFrom();?>"
              value="<?php echo $timeFrom?>""
              />
              <input type="hidden"
              name="<?php echo $block->getNameTo();?>"
              value="<?php echo $timeTo?>""
              />
              </div>
              </div>
              <script type="text/javascript">
              require(['jquery', 'jquery/ui'], function($)
              $("#slider-range").slider(
              range: true,
              min: 0,
              max: 1440,
              step: 15,
              values: [<?php echo $timeFrom?>, <?php echo $timeTo?>],
              slide: function (e, ui)
              var hours1 = Math.floor(ui.values[0] / 60);
              var minutes1 = ui.values[0] - (hours1 * 60);

              if (hours1.length == 1) hours1 = '0' + hours1;
              if (minutes1.length == 1) minutes1 = '0' + minutes1;
              if (minutes1 == 0) minutes1 = '00';
              if (hours1 >= 12)
              if (hours1 == 12)
              hours1 = hours1;
              minutes1 = minutes1 + " PM";
              else
              hours1 = hours1 - 12;
              minutes1 = minutes1 + " PM";

              else
              hours1 = hours1;
              minutes1 = minutes1 + " AM";

              if (hours1 == 0)
              hours1 = 12;
              minutes1 = minutes1;



              $('.slider-time').html(hours1 + ':' + minutes1);

              var hours2 = Math.floor(ui.values[1] / 60);
              var minutes2 = ui.values[1] - (hours2 * 60);

              if (hours2.length == 1) hours2 = '0' + hours2;
              if (minutes2.length == 1) minutes2 = '0' + minutes2;
              if (minutes2 == 0) minutes2 = '00';
              if (hours2 >= 12)
              if (hours2 == 12)
              hours2 = hours2;
              minutes2 = minutes2 + " PM";
              else if (hours2 == 24)
              hours2 = 11;
              minutes2 = "59 PM";
              else
              hours2 = hours2 - 12;
              minutes2 = minutes2 + " PM";

              else
              hours2 = hours2;
              minutes2 = minutes2 + " AM";


              $('.slider-time2').html(hours2 + ':' + minutes2);
              $('[name="<?php echo $block->getNameFrom();?>"]').val(ui.values[0]);
              $('[name="<?php echo $block->getNameTo();?>"]').val(ui.values[1]);

              );
              );
              </script>


              That's all. Based on this example you can modify code to add base features like a use global value etc.



              Here is full code on the GitHub.



              PS: Example partially taken from the Shipping Suite Ultimate Extension by MageWorx (where that kind of slider used in the form).



              PPS: in the example time stored in the database in minutes, like 120 => 2:00 AM.






              share|improve this answer

























                1












                1








                1







                If you wish to add time from/to elements as a slider, you can customize an element frontend model and add your own template.



                How it will be looking



                Here is my example (ported from the regular form to the store configuration section):



                Field in the system.xml:



                <field id="delivery_time" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                <label>Delivery Time</label>
                <frontend_model>MageWorxExampleConfigModelConfigFrontendModelDeliveryTime</frontend_model>
                </field>


                Note: real values will be stored with the delivery_time_from and delivery_time_to indexes.



                Frontend model, where I have replaced the default output of the element:



                <?php

                namespace MageWorxExampleConfigModelConfigFrontendModel;


                class DeliveryTime extends MagentoConfigBlockSystemConfigFormField

                /**
                * Retrieve element HTML markup
                *
                * @param MagentoFrameworkDataFormElementAbstractElement $element
                * @return string
                * @throws MagentoFrameworkExceptionLocalizedException
                */
                protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element)

                $renderer = $this->getLayout()->createBlock(
                'MageWorxExampleConfigBlockTimeSlider'
                );
                $renderer->setElement($element);

                return $renderer->toHtml();




                here we just using a block MageWorxExampleConfigBlockTimeSlider instead of general render.



                And here is the block with template (where slider was defined):



                <?php

                namespace MageWorxExampleConfigBlock;

                use MagentoFrameworkDataFormElementAbstractElement;

                /**
                * Class TimeSlider
                */
                class TimeSlider extends MagentoFrameworkViewElementTemplate implements
                MagentoFrameworkDataFormElementRendererRendererInterface,
                MagentoWidgetBlockBlockInterface


                const TIME_NAME_FROM = 'groups[main][fields][delivery_time_from][value]';
                const TIME_NAME_TO = 'groups[main][fields][delivery_time_to][value]';

                /**
                * Form element which re-rendering
                *
                * @var MagentoFrameworkDataFormElementFieldset
                */
                protected $element;

                /**
                * @var string
                */
                protected $_template = 'MageWorx_ExampleConfig::form/renderer/timeslider.phtml';

                /**
                * @var string
                */
                protected $_htmlId = 'time-range';

                /**
                * Retrieve an element
                *
                * @return MagentoFrameworkDataFormElementFieldset
                */
                public function getElement()

                return $this->element;


                /**
                * Set an element
                *
                * @param AbstractElement $element
                * @return $this
                */
                public function setElement(MagentoFrameworkDataFormElementAbstractElement $element)

                $this->element = $element;

                return $this;


                /**
                * Render element
                *
                * @param AbstractElement $element
                * @return string
                */
                public function render(AbstractElement $element)

                $this->element = $element;

                return $this->toHtml();


                /**
                * @return string
                */
                public function getHtmlId()

                return $this->_htmlId;


                /**
                * @return string
                */
                public function getNameFrom()

                return self::TIME_NAME_FROM;


                /**
                * @return string
                */
                public function getNameTo()

                return self::TIME_NAME_TO;


                /**
                * @param int $minutes
                * @return string
                */
                public function minutesToTime($minutes)

                $hours = floor($minutes / 60);
                $minutes = $minutes % 60;
                $part = $hours >= 12 ? 'PM' : 'AM';

                return sprintf('%02d:%02d %s', $hours, $minutes, $part);


                /**
                * @return string
                * @throws MagentoFrameworkExceptionValidatorException
                */
                protected function _toHtml()

                if (!$this->getTemplate())
                return '';


                return $this->fetchView($this->getTemplateFile());




                Note: you should change values of the constants TIME_NAME_FROM and TIME_NAME_TO to own ones, according your definition in the system.xml.



                Template:



                <?php

                /** @var MageWorxExampleConfigBlockTimeSlider $block */
                $element = $block->getElement();
                $form = $element->getForm();
                /** @var MagentoConfigBlockSystemConfigForm $parentForm */
                $parentForm = $form->getParent();
                $timeFrom = $parentForm->getConfigValue('example_config/main/delivery_time_from');;
                $timeTo = $parentForm->getConfigValue('example_config/main/delivery_time_to');;
                ?>
                <div id="time-range" class="field field-time_range">
                <label class="label" style="white-space: normal;">
                <?php echo __('Time Range: ');?>
                <span class="slider-time">
                <?php echo $block->minutesToTime($timeFrom);?>
                </span>
                <?php echo ' - '; ?>
                <span class="slider-time2">
                <?php echo $block->minutesToTime($timeTo);?>
                </span>
                </label>
                <div class="sliders_step1 control">
                <div id="slider-range"></div>
                <input type="hidden"
                name="<?php echo $block->getNameFrom();?>"
                value="<?php echo $timeFrom?>""
                />
                <input type="hidden"
                name="<?php echo $block->getNameTo();?>"
                value="<?php echo $timeTo?>""
                />
                </div>
                </div>
                <script type="text/javascript">
                require(['jquery', 'jquery/ui'], function($)
                $("#slider-range").slider(
                range: true,
                min: 0,
                max: 1440,
                step: 15,
                values: [<?php echo $timeFrom?>, <?php echo $timeTo?>],
                slide: function (e, ui)
                var hours1 = Math.floor(ui.values[0] / 60);
                var minutes1 = ui.values[0] - (hours1 * 60);

                if (hours1.length == 1) hours1 = '0' + hours1;
                if (minutes1.length == 1) minutes1 = '0' + minutes1;
                if (minutes1 == 0) minutes1 = '00';
                if (hours1 >= 12)
                if (hours1 == 12)
                hours1 = hours1;
                minutes1 = minutes1 + " PM";
                else
                hours1 = hours1 - 12;
                minutes1 = minutes1 + " PM";

                else
                hours1 = hours1;
                minutes1 = minutes1 + " AM";

                if (hours1 == 0)
                hours1 = 12;
                minutes1 = minutes1;



                $('.slider-time').html(hours1 + ':' + minutes1);

                var hours2 = Math.floor(ui.values[1] / 60);
                var minutes2 = ui.values[1] - (hours2 * 60);

                if (hours2.length == 1) hours2 = '0' + hours2;
                if (minutes2.length == 1) minutes2 = '0' + minutes2;
                if (minutes2 == 0) minutes2 = '00';
                if (hours2 >= 12)
                if (hours2 == 12)
                hours2 = hours2;
                minutes2 = minutes2 + " PM";
                else if (hours2 == 24)
                hours2 = 11;
                minutes2 = "59 PM";
                else
                hours2 = hours2 - 12;
                minutes2 = minutes2 + " PM";

                else
                hours2 = hours2;
                minutes2 = minutes2 + " AM";


                $('.slider-time2').html(hours2 + ':' + minutes2);
                $('[name="<?php echo $block->getNameFrom();?>"]').val(ui.values[0]);
                $('[name="<?php echo $block->getNameTo();?>"]').val(ui.values[1]);

                );
                );
                </script>


                That's all. Based on this example you can modify code to add base features like a use global value etc.



                Here is full code on the GitHub.



                PS: Example partially taken from the Shipping Suite Ultimate Extension by MageWorx (where that kind of slider used in the form).



                PPS: in the example time stored in the database in minutes, like 120 => 2:00 AM.






                share|improve this answer













                If you wish to add time from/to elements as a slider, you can customize an element frontend model and add your own template.



                How it will be looking



                Here is my example (ported from the regular form to the store configuration section):



                Field in the system.xml:



                <field id="delivery_time" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                <label>Delivery Time</label>
                <frontend_model>MageWorxExampleConfigModelConfigFrontendModelDeliveryTime</frontend_model>
                </field>


                Note: real values will be stored with the delivery_time_from and delivery_time_to indexes.



                Frontend model, where I have replaced the default output of the element:



                <?php

                namespace MageWorxExampleConfigModelConfigFrontendModel;


                class DeliveryTime extends MagentoConfigBlockSystemConfigFormField

                /**
                * Retrieve element HTML markup
                *
                * @param MagentoFrameworkDataFormElementAbstractElement $element
                * @return string
                * @throws MagentoFrameworkExceptionLocalizedException
                */
                protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element)

                $renderer = $this->getLayout()->createBlock(
                'MageWorxExampleConfigBlockTimeSlider'
                );
                $renderer->setElement($element);

                return $renderer->toHtml();




                here we just using a block MageWorxExampleConfigBlockTimeSlider instead of general render.



                And here is the block with template (where slider was defined):



                <?php

                namespace MageWorxExampleConfigBlock;

                use MagentoFrameworkDataFormElementAbstractElement;

                /**
                * Class TimeSlider
                */
                class TimeSlider extends MagentoFrameworkViewElementTemplate implements
                MagentoFrameworkDataFormElementRendererRendererInterface,
                MagentoWidgetBlockBlockInterface


                const TIME_NAME_FROM = 'groups[main][fields][delivery_time_from][value]';
                const TIME_NAME_TO = 'groups[main][fields][delivery_time_to][value]';

                /**
                * Form element which re-rendering
                *
                * @var MagentoFrameworkDataFormElementFieldset
                */
                protected $element;

                /**
                * @var string
                */
                protected $_template = 'MageWorx_ExampleConfig::form/renderer/timeslider.phtml';

                /**
                * @var string
                */
                protected $_htmlId = 'time-range';

                /**
                * Retrieve an element
                *
                * @return MagentoFrameworkDataFormElementFieldset
                */
                public function getElement()

                return $this->element;


                /**
                * Set an element
                *
                * @param AbstractElement $element
                * @return $this
                */
                public function setElement(MagentoFrameworkDataFormElementAbstractElement $element)

                $this->element = $element;

                return $this;


                /**
                * Render element
                *
                * @param AbstractElement $element
                * @return string
                */
                public function render(AbstractElement $element)

                $this->element = $element;

                return $this->toHtml();


                /**
                * @return string
                */
                public function getHtmlId()

                return $this->_htmlId;


                /**
                * @return string
                */
                public function getNameFrom()

                return self::TIME_NAME_FROM;


                /**
                * @return string
                */
                public function getNameTo()

                return self::TIME_NAME_TO;


                /**
                * @param int $minutes
                * @return string
                */
                public function minutesToTime($minutes)

                $hours = floor($minutes / 60);
                $minutes = $minutes % 60;
                $part = $hours >= 12 ? 'PM' : 'AM';

                return sprintf('%02d:%02d %s', $hours, $minutes, $part);


                /**
                * @return string
                * @throws MagentoFrameworkExceptionValidatorException
                */
                protected function _toHtml()

                if (!$this->getTemplate())
                return '';


                return $this->fetchView($this->getTemplateFile());




                Note: you should change values of the constants TIME_NAME_FROM and TIME_NAME_TO to own ones, according your definition in the system.xml.



                Template:



                <?php

                /** @var MageWorxExampleConfigBlockTimeSlider $block */
                $element = $block->getElement();
                $form = $element->getForm();
                /** @var MagentoConfigBlockSystemConfigForm $parentForm */
                $parentForm = $form->getParent();
                $timeFrom = $parentForm->getConfigValue('example_config/main/delivery_time_from');;
                $timeTo = $parentForm->getConfigValue('example_config/main/delivery_time_to');;
                ?>
                <div id="time-range" class="field field-time_range">
                <label class="label" style="white-space: normal;">
                <?php echo __('Time Range: ');?>
                <span class="slider-time">
                <?php echo $block->minutesToTime($timeFrom);?>
                </span>
                <?php echo ' - '; ?>
                <span class="slider-time2">
                <?php echo $block->minutesToTime($timeTo);?>
                </span>
                </label>
                <div class="sliders_step1 control">
                <div id="slider-range"></div>
                <input type="hidden"
                name="<?php echo $block->getNameFrom();?>"
                value="<?php echo $timeFrom?>""
                />
                <input type="hidden"
                name="<?php echo $block->getNameTo();?>"
                value="<?php echo $timeTo?>""
                />
                </div>
                </div>
                <script type="text/javascript">
                require(['jquery', 'jquery/ui'], function($)
                $("#slider-range").slider(
                range: true,
                min: 0,
                max: 1440,
                step: 15,
                values: [<?php echo $timeFrom?>, <?php echo $timeTo?>],
                slide: function (e, ui)
                var hours1 = Math.floor(ui.values[0] / 60);
                var minutes1 = ui.values[0] - (hours1 * 60);

                if (hours1.length == 1) hours1 = '0' + hours1;
                if (minutes1.length == 1) minutes1 = '0' + minutes1;
                if (minutes1 == 0) minutes1 = '00';
                if (hours1 >= 12)
                if (hours1 == 12)
                hours1 = hours1;
                minutes1 = minutes1 + " PM";
                else
                hours1 = hours1 - 12;
                minutes1 = minutes1 + " PM";

                else
                hours1 = hours1;
                minutes1 = minutes1 + " AM";

                if (hours1 == 0)
                hours1 = 12;
                minutes1 = minutes1;



                $('.slider-time').html(hours1 + ':' + minutes1);

                var hours2 = Math.floor(ui.values[1] / 60);
                var minutes2 = ui.values[1] - (hours2 * 60);

                if (hours2.length == 1) hours2 = '0' + hours2;
                if (minutes2.length == 1) minutes2 = '0' + minutes2;
                if (minutes2 == 0) minutes2 = '00';
                if (hours2 >= 12)
                if (hours2 == 12)
                hours2 = hours2;
                minutes2 = minutes2 + " PM";
                else if (hours2 == 24)
                hours2 = 11;
                minutes2 = "59 PM";
                else
                hours2 = hours2 - 12;
                minutes2 = minutes2 + " PM";

                else
                hours2 = hours2;
                minutes2 = minutes2 + " AM";


                $('.slider-time2').html(hours2 + ':' + minutes2);
                $('[name="<?php echo $block->getNameFrom();?>"]').val(ui.values[0]);
                $('[name="<?php echo $block->getNameTo();?>"]').val(ui.values[1]);

                );
                );
                </script>


                That's all. Based on this example you can modify code to add base features like a use global value etc.



                Here is full code on the GitHub.



                PS: Example partially taken from the Shipping Suite Ultimate Extension by MageWorx (where that kind of slider used in the form).



                PPS: in the example time stored in the database in minutes, like 120 => 2:00 AM.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 14 hours ago









                Siarhey UchukhlebauSiarhey Uchukhlebau

                10.1k93058




                10.1k93058























                    2














                    I would suggest to use the same way magento uses for saving time.



                    In your admin panel, goto




                    Stores -> Configuration -> Advanced -> System -> Scheduled Backup Settings




                    See the Start Time field.



                    enter image description here



                    You may use the same thing in your system.xml file. It seems more accurate.



                    Let me know if you need a code sample for that. I have used the same in one of my module.





                    etc/adminhtml/system.xml





                    <field id="opening_time" translate="label" type="time" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="40">
                    <label>Opening Time</label>
                    </field>


                    Just add above field in system.xml and it will work as per magento standard. It will save time like 15,25,00. The type='time' makes it work. Thats it. No additional coding is needed.






                    share|improve this answer

























                    • can you include code for this one so that I can check

                      – magefms
                      2 days ago











                    • Edited answer with the code. Please check.

                      – Yash Shah
                      2 days ago











                    • okay, I will update you if it works

                      – magefms
                      2 days ago















                    2














                    I would suggest to use the same way magento uses for saving time.



                    In your admin panel, goto




                    Stores -> Configuration -> Advanced -> System -> Scheduled Backup Settings




                    See the Start Time field.



                    enter image description here



                    You may use the same thing in your system.xml file. It seems more accurate.



                    Let me know if you need a code sample for that. I have used the same in one of my module.





                    etc/adminhtml/system.xml





                    <field id="opening_time" translate="label" type="time" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="40">
                    <label>Opening Time</label>
                    </field>


                    Just add above field in system.xml and it will work as per magento standard. It will save time like 15,25,00. The type='time' makes it work. Thats it. No additional coding is needed.






                    share|improve this answer

























                    • can you include code for this one so that I can check

                      – magefms
                      2 days ago











                    • Edited answer with the code. Please check.

                      – Yash Shah
                      2 days ago











                    • okay, I will update you if it works

                      – magefms
                      2 days ago













                    2












                    2








                    2







                    I would suggest to use the same way magento uses for saving time.



                    In your admin panel, goto




                    Stores -> Configuration -> Advanced -> System -> Scheduled Backup Settings




                    See the Start Time field.



                    enter image description here



                    You may use the same thing in your system.xml file. It seems more accurate.



                    Let me know if you need a code sample for that. I have used the same in one of my module.





                    etc/adminhtml/system.xml





                    <field id="opening_time" translate="label" type="time" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="40">
                    <label>Opening Time</label>
                    </field>


                    Just add above field in system.xml and it will work as per magento standard. It will save time like 15,25,00. The type='time' makes it work. Thats it. No additional coding is needed.






                    share|improve this answer















                    I would suggest to use the same way magento uses for saving time.



                    In your admin panel, goto




                    Stores -> Configuration -> Advanced -> System -> Scheduled Backup Settings




                    See the Start Time field.



                    enter image description here



                    You may use the same thing in your system.xml file. It seems more accurate.



                    Let me know if you need a code sample for that. I have used the same in one of my module.





                    etc/adminhtml/system.xml





                    <field id="opening_time" translate="label" type="time" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="40">
                    <label>Opening Time</label>
                    </field>


                    Just add above field in system.xml and it will work as per magento standard. It will save time like 15,25,00. The type='time' makes it work. Thats it. No additional coding is needed.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 2 days ago

























                    answered 2 days ago









                    Yash ShahYash Shah

                    78118




                    78118












                    • can you include code for this one so that I can check

                      – magefms
                      2 days ago











                    • Edited answer with the code. Please check.

                      – Yash Shah
                      2 days ago











                    • okay, I will update you if it works

                      – magefms
                      2 days ago

















                    • can you include code for this one so that I can check

                      – magefms
                      2 days ago











                    • Edited answer with the code. Please check.

                      – Yash Shah
                      2 days ago











                    • okay, I will update you if it works

                      – magefms
                      2 days ago
















                    can you include code for this one so that I can check

                    – magefms
                    2 days ago





                    can you include code for this one so that I can check

                    – magefms
                    2 days ago













                    Edited answer with the code. Please check.

                    – Yash Shah
                    2 days ago





                    Edited answer with the code. Please check.

                    – Yash Shah
                    2 days ago













                    okay, I will update you if it works

                    – magefms
                    2 days ago





                    okay, I will update you if it works

                    – magefms
                    2 days ago











                    1














                    You can follow steps below to show Datetime field in your custom module admin config section



                    step 1) Create system.xml under ***app/code/Vendor/Module/etc/adminFile:*



                    File : app/code/Vendor/MyModule/etc/adminhtml/system.xml



                    <?xml version="1.0"?>

                    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
                    <system>
                    <tab id="mycustom" translate="label" sortOrder="450">
                    <label>My Custom Setting</label>
                    </tab>
                    <section id="mycustom" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
                    <class>separator-top</class>
                    <label>My Custom Setting</label>
                    <tab>mycustom</tab>
                    <resource>Magento_Checkout::config</resource>
                    <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <field id="mydate" translate="label" type="date" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>My Date Field</label>
                    <frontend_model>VendorMyModuleBlockAdminhtmlSystemConfigDateTime</frontend_model>
                    </field>
                    </group>
                    </section>
                    </system>
                    </config>


                    step 2) Create the block DateTime.php under /app/code/Vendor/MyModule/Block/Adminhtml/System/Config/DateTime.php



                    File : /app/code/Vendor/MyModule/Block/Adminhtml/System/Config/DateTime.php



                    <?php

                    namespace VendorMyModuleBlockAdminhtmlSystemConfig;

                    class DateTime extends MagentoConfigBlockSystemConfigFormField


                    protected $timezone;

                    public function __construct(
                    MagentoBackendBlockTemplateContext $context,
                    MagentoFrameworkStdlibDateTimeTimezoneInterface $timezone,
                    array $data = []
                    )
                    $this->timezone = $timezone;
                    parent::__construct($context, $data);


                    public function render(MagentoFrameworkDataFormElementAbstractElement $element)

                    $element->setDateFormat($this->timezone->getDateFormat());
                    $element->setTimeFormat($this->timezone->getTimeFormat());
                    $element->setShowsTime(true);
                    return parent::render($element);




                    step 3: Run Following commands



                    sudo php bin/magento setup:di:compile
                    sudo php bin/magento cache:flush


                    step 4: Check your custom module admin config section for newly added datetime config field.



                    enter image description here






                    share|improve this answer























                    • Thanks for the answer bro, but I have done that already, please review my requirement, I need time picker only.

                      – magefms
                      2 days ago















                    1














                    You can follow steps below to show Datetime field in your custom module admin config section



                    step 1) Create system.xml under ***app/code/Vendor/Module/etc/adminFile:*



                    File : app/code/Vendor/MyModule/etc/adminhtml/system.xml



                    <?xml version="1.0"?>

                    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
                    <system>
                    <tab id="mycustom" translate="label" sortOrder="450">
                    <label>My Custom Setting</label>
                    </tab>
                    <section id="mycustom" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
                    <class>separator-top</class>
                    <label>My Custom Setting</label>
                    <tab>mycustom</tab>
                    <resource>Magento_Checkout::config</resource>
                    <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <field id="mydate" translate="label" type="date" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>My Date Field</label>
                    <frontend_model>VendorMyModuleBlockAdminhtmlSystemConfigDateTime</frontend_model>
                    </field>
                    </group>
                    </section>
                    </system>
                    </config>


                    step 2) Create the block DateTime.php under /app/code/Vendor/MyModule/Block/Adminhtml/System/Config/DateTime.php



                    File : /app/code/Vendor/MyModule/Block/Adminhtml/System/Config/DateTime.php



                    <?php

                    namespace VendorMyModuleBlockAdminhtmlSystemConfig;

                    class DateTime extends MagentoConfigBlockSystemConfigFormField


                    protected $timezone;

                    public function __construct(
                    MagentoBackendBlockTemplateContext $context,
                    MagentoFrameworkStdlibDateTimeTimezoneInterface $timezone,
                    array $data = []
                    )
                    $this->timezone = $timezone;
                    parent::__construct($context, $data);


                    public function render(MagentoFrameworkDataFormElementAbstractElement $element)

                    $element->setDateFormat($this->timezone->getDateFormat());
                    $element->setTimeFormat($this->timezone->getTimeFormat());
                    $element->setShowsTime(true);
                    return parent::render($element);




                    step 3: Run Following commands



                    sudo php bin/magento setup:di:compile
                    sudo php bin/magento cache:flush


                    step 4: Check your custom module admin config section for newly added datetime config field.



                    enter image description here






                    share|improve this answer























                    • Thanks for the answer bro, but I have done that already, please review my requirement, I need time picker only.

                      – magefms
                      2 days ago













                    1












                    1








                    1







                    You can follow steps below to show Datetime field in your custom module admin config section



                    step 1) Create system.xml under ***app/code/Vendor/Module/etc/adminFile:*



                    File : app/code/Vendor/MyModule/etc/adminhtml/system.xml



                    <?xml version="1.0"?>

                    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
                    <system>
                    <tab id="mycustom" translate="label" sortOrder="450">
                    <label>My Custom Setting</label>
                    </tab>
                    <section id="mycustom" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
                    <class>separator-top</class>
                    <label>My Custom Setting</label>
                    <tab>mycustom</tab>
                    <resource>Magento_Checkout::config</resource>
                    <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <field id="mydate" translate="label" type="date" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>My Date Field</label>
                    <frontend_model>VendorMyModuleBlockAdminhtmlSystemConfigDateTime</frontend_model>
                    </field>
                    </group>
                    </section>
                    </system>
                    </config>


                    step 2) Create the block DateTime.php under /app/code/Vendor/MyModule/Block/Adminhtml/System/Config/DateTime.php



                    File : /app/code/Vendor/MyModule/Block/Adminhtml/System/Config/DateTime.php



                    <?php

                    namespace VendorMyModuleBlockAdminhtmlSystemConfig;

                    class DateTime extends MagentoConfigBlockSystemConfigFormField


                    protected $timezone;

                    public function __construct(
                    MagentoBackendBlockTemplateContext $context,
                    MagentoFrameworkStdlibDateTimeTimezoneInterface $timezone,
                    array $data = []
                    )
                    $this->timezone = $timezone;
                    parent::__construct($context, $data);


                    public function render(MagentoFrameworkDataFormElementAbstractElement $element)

                    $element->setDateFormat($this->timezone->getDateFormat());
                    $element->setTimeFormat($this->timezone->getTimeFormat());
                    $element->setShowsTime(true);
                    return parent::render($element);




                    step 3: Run Following commands



                    sudo php bin/magento setup:di:compile
                    sudo php bin/magento cache:flush


                    step 4: Check your custom module admin config section for newly added datetime config field.



                    enter image description here






                    share|improve this answer













                    You can follow steps below to show Datetime field in your custom module admin config section



                    step 1) Create system.xml under ***app/code/Vendor/Module/etc/adminFile:*



                    File : app/code/Vendor/MyModule/etc/adminhtml/system.xml



                    <?xml version="1.0"?>

                    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
                    <system>
                    <tab id="mycustom" translate="label" sortOrder="450">
                    <label>My Custom Setting</label>
                    </tab>
                    <section id="mycustom" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
                    <class>separator-top</class>
                    <label>My Custom Setting</label>
                    <tab>mycustom</tab>
                    <resource>Magento_Checkout::config</resource>
                    <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <field id="mydate" translate="label" type="date" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>My Date Field</label>
                    <frontend_model>VendorMyModuleBlockAdminhtmlSystemConfigDateTime</frontend_model>
                    </field>
                    </group>
                    </section>
                    </system>
                    </config>


                    step 2) Create the block DateTime.php under /app/code/Vendor/MyModule/Block/Adminhtml/System/Config/DateTime.php



                    File : /app/code/Vendor/MyModule/Block/Adminhtml/System/Config/DateTime.php



                    <?php

                    namespace VendorMyModuleBlockAdminhtmlSystemConfig;

                    class DateTime extends MagentoConfigBlockSystemConfigFormField


                    protected $timezone;

                    public function __construct(
                    MagentoBackendBlockTemplateContext $context,
                    MagentoFrameworkStdlibDateTimeTimezoneInterface $timezone,
                    array $data = []
                    )
                    $this->timezone = $timezone;
                    parent::__construct($context, $data);


                    public function render(MagentoFrameworkDataFormElementAbstractElement $element)

                    $element->setDateFormat($this->timezone->getDateFormat());
                    $element->setTimeFormat($this->timezone->getTimeFormat());
                    $element->setShowsTime(true);
                    return parent::render($element);




                    step 3: Run Following commands



                    sudo php bin/magento setup:di:compile
                    sudo php bin/magento cache:flush


                    step 4: Check your custom module admin config section for newly added datetime config field.



                    enter image description here







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 2 days ago









                    Pritam Info 24Pritam Info 24

                    79217




                    79217












                    • Thanks for the answer bro, but I have done that already, please review my requirement, I need time picker only.

                      – magefms
                      2 days ago

















                    • Thanks for the answer bro, but I have done that already, please review my requirement, I need time picker only.

                      – magefms
                      2 days ago
















                    Thanks for the answer bro, but I have done that already, please review my requirement, I need time picker only.

                    – magefms
                    2 days ago





                    Thanks for the answer bro, but I have done that already, please review my requirement, I need time picker only.

                    – magefms
                    2 days ago

















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f269454%2fhow-to-implement-time-range-picker-in-magento-2-admin-system-xml%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    یوتیوب محتویات پیشینه[ویرایش] فناوری‌های ویدئویی[ویرایش] شوخی‌های آوریل[ویرایش] سانسور و فیلترینگ[ویرایش] آمار و ارقامی از یوتیوب[ویرایش] تأثیر اجتماعی[ویرایش] سیاست اجتماعی[ویرایش] نمودارها[ویرایش] یادداشت‌ها[ویرایش] پانویس[ویرایش] پیوند به بیرون[ویرایش] منوی ناوبریبررسی شده‌استYouTube.com[بروزرسانی]"Youtube.com Site Info""زبان‌های یوتیوب""Surprise! There's a third YouTube co-founder"سایت یوتیوب برای چندمین بار در ایران فیلتر شدنسخهٔ اصلیسالار کمانگر جوان آمریکایی ایرانی الاصل مدیر سایت یوتیوب شدنسخهٔ اصلیVideo websites pop up, invite postingsthe originalthe originalYouTube: Overnight success has sparked a backlashthe original"Me at the zoo"YouTube serves up 100 million videos a day onlinethe originalcomScore Releases May 2010 U.S. Online Video Rankingsthe originalYouTube hits 4 billion daily video viewsthe originalYouTube users uploading two days of video every minutethe originalEric Schmidt, Princeton Colloquium on Public & Int'l Affairsthe original«Streaming Dreams»نسخهٔ اصلیAlexa Traffic Rank for YouTube (three month average)the originalHelp! YouTube is killing my business!the originalUtube sues YouTubethe originalGoogle closes $A2b YouTube dealthe originalFlash moves on to smart phonesthe originalYouTube HTML5 Video Playerنسخهٔ اصلیYouTube HTML5 Video Playerthe originalGoogle tries freeing Web video with WebMthe originalVideo length for uploadingthe originalYouTube caps video lengths to reduce infringementthe originalAccount Types: Longer videosthe originalYouTube bumps video limit to 15 minutesthe originalUploading large files and resumable uploadingthe originalVideo Formats: File formatsthe originalGetting Started: File formatsthe originalThe quest for a new video codec in Flash 8the originalAdobe Flash Video File Format Specification Version 10.1the originalYouTube Mobile goes livethe originalYouTube videos go HD with a simple hackthe originalYouTube now supports 4k-resolution videosthe originalYouTube to get high-def 1080p playerthe original«Approximate YouTube Bitrates»نسخهٔ اصلی«Bigger and Better: Encoding for YouTube 720p HD»نسخهٔ اصلی«YouTube's 1080p – Failure Depends on How You Look At It»نسخهٔ اصلیYouTube in 3Dthe originalYouTube in 3D?the originalYouTube 3D Videosthe originalYouTube adds a dimension, 3D goggles not includedthe originalYouTube Adds Stereoscopic 3D Video Support (And 3D Vision Support, Too)the original«Sharing YouTube Videos»نسخهٔ اصلی«Downloading videos from YouTube is not supported, except for one instance when it is permitted.»نسخهٔ اصلی«Terms of Use, 5.B»نسخهٔ اصلی«Some YouTube videos get download option»نسخهٔ اصلی«YouTube looks out for content owners, disables video ripping»«Downloading videos from YouTube is not supported, except for one instance when it is permitted.»نسخهٔ اصلی«YouTube Hopes To Boost Revenue With Video Downloads»نسخهٔ اصلی«YouTube Mobile»نسخهٔ اصلی«YouTube Live on Apple TV Today; Coming to iPhone on June 29»نسخهٔ اصلی«Goodbye Flash: YouTube mobile goes HTML5 on iPhone and Android»نسخهٔ اصلی«YouTube Mobile Goes HTML5, Video Quality Beats Native Apps Hands Down»نسخهٔ اصلی«TiVo Getting YouTube Streaming Today»نسخهٔ اصلی«YouTube video comes to Wii and PlayStation 3 game consoles»نسخهٔ اصلی«Coming Up Next... YouTube on Your TV»نسخهٔ اصلی«Experience YouTube XL on the Big Screen»نسخهٔ اصلی«Xbox Live Getting Live TV, YouTube & Bing Voice Search»نسخهٔ اصلی«YouTube content locations»نسخهٔ اصلی«April fools: YouTube turns the world up-side-down»نسخهٔ اصلی«YouTube goes back to 1911 for April Fools' Day»نسخهٔ اصلی«Simon Cowell's bromance, the self-driving Nascar and Hungry Hippos for iPad... the best April Fools' gags»نسخهٔ اصلی"YouTube Announces It Will Shut Down""YouTube Adds Darude 'Sandstorm' Button To Its Videos For April Fools' Day"«Censorship fears rise as Iran blocks access to top websites»نسخهٔ اصلی«China 'blocks YouTube video site'»نسخهٔ اصلی«YouTube shut down in Morocco»نسخهٔ اصلی«Thailand blocks access to YouTube»نسخهٔ اصلی«Ban on YouTube lifted after deal»نسخهٔ اصلی«Google's Gatekeepers»نسخهٔ اصلی«Turkey goes into battle with Google»نسخهٔ اصلی«Turkey lifts two-year ban on YouTube»نسخهٔ اصلیسانسور در ترکیه به یوتیوب رسیدلغو فیلترینگ یوتیوب در ترکیه«Pakistan blocks YouTube website»نسخهٔ اصلی«Pakistan lifts the ban on YouTube»نسخهٔ اصلی«Pakistan blocks access to YouTube in internet crackdown»نسخهٔ اصلی«Watchdog urges Libya to stop blocking websites»نسخهٔ اصلی«YouTube»نسخهٔ اصلی«Due to abuses of religion, customs Emirates, YouTube is blocked in the UAE»نسخهٔ اصلی«Google Conquered The Web - An Ultimate Winner»نسخهٔ اصلی«100 million videos are viewed daily on YouTube»نسخهٔ اصلی«Harry and Charlie Davies-Carr: Web gets taste for biting baby»نسخهٔ اصلی«Meet YouTube's 224 million girl, Natalie Tran»نسخهٔ اصلی«YouTube to Double Down on Its 'Channel' Experiment»نسخهٔ اصلی«13 Some Media Companies Choose to Profit From Pirated YouTube Clips»نسخهٔ اصلی«Irate HK man unlikely Web hero»نسخهٔ اصلی«Web Guitar Wizard Revealed at Last»نسخهٔ اصلی«Charlie bit my finger – again!»نسخهٔ اصلی«Lowered Expectations: Web Redefines 'Quality'»نسخهٔ اصلی«YouTube's 50 Greatest Viral Videos»نسخهٔ اصلیYouTube Community Guidelinesthe original«Why did my YouTube account get closed down?»نسخهٔ اصلی«Why do I have a sanction on my account?»نسخهٔ اصلی«Is YouTube's three-strike rule fair to users?»نسخهٔ اصلی«Viacom will sue YouTube for $1bn»نسخهٔ اصلی«Mediaset Files EUR500 Million Suit Vs Google's YouTube»نسخهٔ اصلی«Premier League to take action against YouTube»نسخهٔ اصلی«YouTube law fight 'threatens net'»نسخهٔ اصلی«Google must divulge YouTube log»نسخهٔ اصلی«Google Told to Turn Over User Data of YouTube»نسخهٔ اصلی«US judge tosses out Viacom copyright suit against YouTube»نسخهٔ اصلی«Google and Viacom: YouTube copyright lawsuit back on»نسخهٔ اصلی«Woman can sue over YouTube clip de-posting»نسخهٔ اصلی«YouTube loses court battle over music clips»نسخهٔ اصلیYouTube to Test Software To Ease Licensing Fightsthe original«Press Statistics»نسخهٔ اصلی«Testing YouTube's Audio Content ID System»نسخهٔ اصلی«Content ID disputes»نسخهٔ اصلیYouTube Community Guidelinesthe originalYouTube criticized in Germany over anti-Semitic Nazi videosthe originalFury as YouTube carries sick Hillsboro video insultthe originalYouTube attacked by MPs over sex and violence footagethe originalAl-Awlaki's YouTube Videos Targeted by Rep. Weinerthe originalYouTube Withdraws Cleric's Videosthe originalYouTube is letting users decide on terrorism-related videosthe original«Time's Person of the Year: You»نسخهٔ اصلی«Our top 10 funniest YouTube comments – what are yours?»نسخهٔ اصلی«YouTube's worst comments blocked by filter»نسخهٔ اصلی«Site Info YouTube»نسخهٔ اصلیوبگاه YouTubeوبگاه موبایل YouTubeوووووو

                    Magento 2 - Auto login with specific URL Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Customer can't login - Page refreshes but nothing happensCustom Login page redirectURL to login with redirect URL after completionCustomer login is case sensitiveLogin with phone number or email address - Magento 1.9Magento 2: Set Customer Account Confirmation StatusCustomer auto connect from URLHow to call customer login form in the custom module action magento 2?Change of customer login error message magento2Referrer URL in modal login form

                    Rest API with Magento using PHP with example. Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How to update product using magento client library for PHP?Oauth Error while extending Magento Rest APINot showing my custom api in wsdl(url) and web service list?Using Magento API(REST) via IXMLHTTPRequest COM ObjectHow to login in Magento website using REST APIREST api call for Guest userMagento API calling using HTML and javascriptUse API rest media management by storeView code (admin)Magento REST API Example ErrorsHow to log all rest api calls in magento2?How to update product using magento client library for PHP?