DatePicker minDate relative 1 month from the start date

How to set #endDatePicker 1 month to the future of the selected date from #startDatePicker?

I do not understand this, but I am sure it is easier than I do it.

Here is what I start with. Now I need a function that calculates exactly 1 month (not only 30 days) in the future based on the selected date from #startDatePicker.

    $("#startDatePicker").datepicker({
        minDate: +0,
    });

    $("#endDatePicker").datepicker({
        minDate: '+1m',
        beforeShow: customMinDate
    });

Any help was appreciated.

+3
source share
1 answer

Not sure what you mean by β€œnot only 30 days,” but that should do what you want.

$("#endDatePicker").datepicker({
    minDate: '+1m',
    beforeShow: function() {
        //get date startDate is set to
        var startDate = $("#startDatePicker").datepicker('getDate');
        //if a date was selected else do nothing
        if (startDate != null) {
            startDate.setMonth(startDate.getMonth()+1);
            $(this).datepicker('option', 'minDate',startDate);
        }
    }
});
+10
source

Source: https://habr.com/ru/post/1723936/


All Articles