I have two text fields. In the first textfield I have added a calendar using jQueryUI Datepicker. When the user selects the date from the datepicker, it should automatically add 30 days to the date and set this value in the second textfield. I've got this working to add 30 days to the date.
However, it should exclude weekends and holidays and display only 30 business days. How do I do this?
if ($('#cat option:selected').text() == "ABC") {
var date_billed = $('#datebilled').datepicker('getDate');
var date_overdue = new Date();
date_overdue.setDate(date_billed.getDate() + 30);
date_overdue = $.datepicker.formatDate('mm/dd/yy', date_overdue);
$('#datepd').val(date_overdue).prop('readonly', true);
}
Update: I have added the function noWeekendsOrHolidays to disable weekends or holidays. Is there anyway I can use this function to calculate and add business days to the date?
//holidays
var natDays = [
[7, 4, 'us']
];
function noWeekendsOrHolidays(date) {
var noWeekend = $.datepicker.noWeekends(date);
if (noWeekend[0]) {
return nationalDays(date);
} else {
return noWeekend;
}
}
function nationalDays(date) {
for (i = 0; i < natDays.length; i++) {
if (date.getMonth() == natDays[i][0] - 1 && date.getDate() == natDays[i][1]) {
return [false, natDays[i][2] + '_day'];
}
}
return [true, ''];
}