Bootstrap datepicker how to resolve last 6 months

How can I include the last 6 months from today, including today in Bootstrap datepicke.

For example, if today is October 4, 2015, then the calendar will allow you to select any date from April 4, 2015 to October 4, 2015.

    var date = new Date();
    // initialize daterange
    $('.input-daterange').datepicker({
        format: "mm/dd/yy",
        orientation: "top left",
        autoclose: true,
        todayHighlight: false,
        toggleActive: false,
        startDate: date
    });
+4
source share
2 answers

startDategotta do it ( doc )

+1
source

I assume you are using this , so you can use endDateand startDate.

You need to install startDateon Date.now - 6 monthsand endDatetoday.

var now = new Date();
var sixmonthsago = new Date(d.setMonth(d.getMonth() - 6));


$('.input-daterange').datepicker({
    format: "mm/dd/yy",
    orientation: "top left",
    autoclose: true,
    todayHighlight: false,
    toggleActive: false,
    endDate: now,
    startDate: sixmonthsago
});

I have not tested the code.

+1
source

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


All Articles