Search code examples
wordpressjquery-uidatepickercalendarhour

I set ui datepicker to disable all day before tomorrow, but the hours?


I disable ui datepicker all days before tomorrow with "minDate: 1", but I have problems with the hours because the slide hours starts in 00:00. I use js/jquery/ui/datepicker.min.js?ver=1.11.4 in Wordpress. Example, today is February 21 and is disabled before tomorrow, it is 23:00 pm hours, but as the slide of the hours starts at 00:00. The user can select Febrery 22 at 00:00, only one hour before and not 24 hours before or one day. How can I do this? I put code and pictures below:

        $('.departure-date').datetimepicker({
            minDate: 1,
            // minTime: '12:00',
            // maxTime: '11:59',
            teFormat: window.datepickerDateFormat,
            altFormat: window.datepickerAltFormat,
            altFieldTimeOnly: false,
            showMillisec: false,
            showMicrosec: false,
            showTimezone: false,
            numberOfMonths: 1,
            altField: "#dep",
            addSliderAccess: true,
            sliderAccessArgs: { touchonly: true },
        });

example1 and example2 Can someone help me please?


Solution

  • There are some holes in documentation so looking into the plugin code I found way to do what you want. Two options:

    1. Add just one line to params array you have (change X to hours amount):

      minDateTime:(new Date()).setTime((new Date()).getTime() + (X*60*60*1000)),
      
    2. Before call your datetimepicker calculate minDateTime and then add short line to params array:

      var startDate = new Date();
      startDate.setTime(startDate.getTime() + (X*60*60*1000));
      
      $('.departure-date').datetimepicker({
          minDateTime: startDate,
          ...
      });