简体   繁体   中英

DateTimePicker: function add remove day from minDate maxDate

I'm having a bit of trouble with the DateTimePicker by XDSOFT. I'm trying to add and remove a day from the minDate and maxDate in the onShow function of the DateTimePicker.

jQuery(function(){
  $('.start-date').datetimepicker({
    format: 'd/m/y H:i',
    onShow: function (ct) {
      this.setOptions({
        maxDate: getEndDate($('#end-date-input').val()),
        formatDate: 'd/m/y H:i'

      })
    },
    timepicker:true,
    onChangeDateTime: function (current_time, $input) {
      var inputDate;
      inputDate = $input.val();
      $('#start-date-input').val(inputDate);
      $('.start-date').children().attr('data-original-title', inputDate);
      console.log(inputDate)

    }
  });
  $('.end-date').datetimepicker({
    format: 'd/m/y H:i',
    onShow: function (ct) {
      this.setOptions({
        minDate: getStartDate($('#start-date-input').val()),
        formatDate: 'd/m/y H:i'
      })

    },
    timepicker:true,
    onChangeDateTime: function (current_time, $input) {
      var inputDate;
      inputDate = $input.val();
      $('#end-date-input').val(inputDate);
      $('.end-date').children().attr('data-original-title', inputDate);
      console.log(inputDate)
    }
  });
});

function getStartDate(date_input) {
  var from_date = new Date(date_input);
  return new Date(from_date.setDate(from_date.getDate() + 1));

}

function getEndDate(date_input) {
  var from_date = new Date(date_input);
  return new Date(from_date.setDate(from_date.getDate() - 1));

}

Is there a problem with my function ?

Months later, but still might help someone.

I think your date might not take properly the "+1" and "-1" on your "from_date.getDate() + 1" and "from_date.getDate() - 1" parts.

It might be understood as "Add 1" or "Remove 1" to the timestamps. try to do something like "+/- 60 * 60 * 24"

Might work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM