Reputation: 153
My goal is to have the first 7 days of each month, and last 5 days of each month disabled in jQuery UI datepicker. I see that there are ways to set maxDate and minDate, however that is specified from the current date.
Problem:
I managed to get the first 7 days disabled, however the last 5 days of each month vary since some end with 28 days or 31 etc.
My code:
$('input, .ui-datepicker').datepicker({
beforeShowDay: function(date) {
if (date.getDate() <= 7) {
return [false, ''];
}
return [true, ''];
}
});
Is there a way to accomplish disabling the last 3 or 5 days of each month
without hardcoding dates from months in an array?
If this is already answered please direct me to the answered question, I haven't found it.
Thank you for your time.
Upvotes: 0
Views: 57
Reputation: 414
You can retrieve the last day of the month in javascript Date library
var lastDay = new Date(y, m + 1, 0).toLocaleDateString("en-US", {day:'numeric'});
Use that as a constraint for an if statement.
Upvotes: 1