1

I want to enable only 3 months from current date in bootstrap datepicker.

function addThreeMonthsToStartDate(today) {
    var lastDate = new Date(today.getFullYear(), today.getMonth()+3, getDate());
    return lastDate;
}

$("#startdate").datepicker({
    isDisabled: function(date) {
        return date.valueOf() < Date.now() ? false : true;
    },
    autoClose: true,
    viewStart: 0,
    weekStart: 1,
    maxDate: lastDate,
    dateFormat: "dd/mm/yyyy"
});

Any ideas?

Aliaxander
  • 2,547
  • 4
  • 20
  • 45
manas
  • 11
  • 1
  • 4

4 Answers4

1

Solution to your problem it allows only 3 months from current date.

 $('#startdate').datepicker({
        maxDate: "+90d",
        minDate:0
    });
S Dhanissh
  • 103
  • 1
  • 1
  • 15
0

Try this

 function addThreeMonthsToStartDate(today) {
 // var today = new Date();
    var lastDate = new Date(today.getFullYear(), today.getMonth()+3, 
                   today.getDate());
    }



$("#startdate").datepicker({
    isDisabled: function(date) {
        return date.valueOf() < Date.now() ? false : true;
    },
    minDate: "dateToday", // If you need to disable past dates
    autoClose: true,
    viewStart: 0,
    weekStart: 1,
    maxDate: lastDate,
    dateFormat: "dd/mm/yyyy"
});
Prasanth Ravi
  • 189
  • 2
  • 14
0

Thanks a lot for your suggestions. I got the solution as below:

    $("#startdate").datepicker({
    isDisabled: function(date) {
        var d = new Date(); 
        return date.valueOf() < d.setMonth(d.getMonth()+3) ? false : true;
    },
    autoClose: true,
    viewStart: 0,
    weekStart: 1,
    maxDate: 0,
    dateFormat: "dd/mm/yyyy"
});
manas
  • 11
  • 1
  • 4
0

you most use startDate and endDate in bootstrap datepicker

 function addThreeMonthsToStartDate(today) {
 // var today = new Date();
    var lastDate = new Date(today.getFullYear(), today.getMonth()+3, 
                   today.getDate());
    }



$("#startdate").datepicker({
    isDisabled: function(date) {
        return date.valueOf() < Date.now() ? false : true;
    },
    startDate: "dateToday", // If you need to disable past dates
    autoClose: true,
    viewStart: 0,
    weekStart: 1,
    endDate: lastDate,
    dateFormat: "dd/mm/yyyy"
});
Abbas Hasani
  • 194
  • 4