JavaScript for getting Total days between of two dates & Exclude the Saturdays and Sundays in total days.
Code:
Code:
function DateDifference() {
var startDate = document.getElementById('<%=
txtStartDate.ClientID%>').value;
var endDate = document.getElementById('<%=
txtEndDate.ClientID%>').value;
var startDateSplit = startDate.split("/");
var endDateSplit = endDate.split("/");
//getting Start Date,End Date
var stDate = new
Date(startDateSplit[2], startDateSplit[0] - 1, startDateSplit[1]);
var enDate = new
Date(endDateSplit[2], endDateSplit[0] - 1, endDateSplit[1]);
//getting difference B/W Start Date & End
Date
var difference = (enDate.getTime() -
stDate.getTime()) / (1000 * 60 * 60 * 24);
var LeaveCount = difference + 1;
if (stDate.getDay() == 0) {
LeaveCount = LeaveCount -
1;
}
else
if (stDate.getDay() == 6) {
LeaveCount = LeaveCount - 1;
}
var loopDate = new
Date();
loopDate = stDate;
// Excluding Sat ,Sun in Selcted Dates
for (var i = 1;
i < difference + 1; i++) {
var NextDate = new
Date(loopDate.getYear(), loopDate.getMonth(), loopDate.getDate() +
1);
var Ndate = NextDate.getMonth() + 1 + "/" + NextDate.getDate() + "/" + NextDate.getYear();
var NdateSplit = Ndate.split("/");
var NxtDate = new
Date(NdateSplit[2], NdateSplit[0] - 1, NdateSplit[1]);
loopDate = NxtDate;
if (NxtDate.getDay() == 0) {
LeaveCount = LeaveCount -
1;
}
else if
(NxtDate.getDay() == 6) {
LeaveCount = LeaveCount - 1;
}
}
document.getElementById('<%=
txtTotalDays.ClientID%>').value
= LeaveCount;
}