infatti
infatti

Reputation: 31

DatePicker minDate relative 1 month from start date

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

I am not figuring this one out but I am sure it is easier than I am making it.

Here is what I am starting out with. Now I need a function that calculates exactly 1 month(not just 30 days) into the future based on the selected date from the #startDatePicker.

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

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

Any help appreciated.

Upvotes: 3

Views: 12071

Answers (1)

jitter
jitter

Reputation: 54605

Not sure what you mean by "not just 30 days" but this 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);
        }
    }
});

Upvotes: 11

Related Questions