How to set minDate and maxDate for bootstrap datetimepicker on change

前端 未结 3 1475
深忆病人
深忆病人 2021-01-06 19:07

I want to ask users for a date range using bootstrap datetimepicker. There is a field for the start date and another one for the end date, and they\'re initialized to the da

相关标签:
3条回答
  • 2021-01-06 19:15

    Based on the Linked Pickers example in the Bootstrap datetimepicker documentation, this should work.

    Start:

     .on('dp.change', function (selected) {
        end.data("DateTimePicker").minDate(selected.date);
     });
    

    End:

     .on('dp.change', function (selected) {
        start.data("DateTimePicker").maxDate(selected.date);
     });
    

    Note:

    On older versions of Bootstrap datetimepicker (less than v4), use .setMinDate and .setMaxDate

    0 讨论(0)
  • 2021-01-06 19:26

    Try to use:

    $('.datepickerProjectDate').data("DateTimePicker").minDate('2018-09-15');
    
    0 讨论(0)
  • 2021-01-06 19:38
    1. Start Date

      .on('dp.change', function (selected) {
          end.data("DateTimePicker").minDate(selected.date);
       });
      
    2. End Date

      .on('dp.change', function (selected) {
          start.data("DateTimePicker").maxDate(selected.date);
       });
      

    Package Upgrade : The date timepicker package has been upgraded to latest version where we can use 'maxDate()' in place of 'setMaxDate()' and 'minDate()' inplace of 'setMinDate()' as the recent options consider even time in hrs and mins while providing maxDate/minDate option.

    0 讨论(0)
提交回复
热议问题