manas
manas

Reputation: 11

How to set 3 months date range from current date in date picker?

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?

Upvotes: 1

Views: 5180

Answers (4)

Abbas Hasani
Abbas Hasani

Reputation: 204

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"
});

Upvotes: 0

manas
manas

Reputation: 11

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"
});

Upvotes: 0

Prasanth Ravi
Prasanth Ravi

Reputation: 189

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"
});

Upvotes: 0

S Dhanissh
S Dhanissh

Reputation: 99

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

 $('#startdate').datepicker({
        maxDate: "+90d",
        minDate:0
    });

Upvotes: 1

Related Questions