Reynier
Reynier

Reputation: 2478

Limit days selection to non past current month only in Bootstrap Datepicker

I'm using bootstrap-datepicker and I need to configure it to allow only selection from current day to end day in the current month, I don't want to allow users to navigate trough months, is that possible? How? I read the docs but doesn't find any really helpful

Upvotes: 1

Views: 2966

Answers (1)

Praveen
Praveen

Reputation: 56501

1) You can use the startDate and endDate options of bootstrap datepicker.

2) Set today's date in startDate

var today = new Date();

3) To get last date of the month use this approach

var lastDate = new Date(today.getFullYear(), today.getMonth() + 1, 0);

Finally

var today = new Date(); //Get today's date
var lastDate = new Date(today.getFullYear(), today.getMonth() + 1, 0);  //To get the last date of today's month
$("#datepicker").datepicker({
    startDate: today,
    endDate: lastDate
});

JSFiddle

Upvotes: 3

Related Questions