Nishu Tayal Nishu Tayal - 1 year ago 84
jQuery Question

Add no. of days in a date to get next date(excluding weekends)

I have an date, i need to add no. of days to get future date but weekends should be excluded.

input date = "9-DEC-2011";
No. of days to add = '13';

next date should be "27-Dec-2011"

Here weekends(sat/sun) are not counted.

Answer Source

Try this

var startDate = "9-DEC-2011";
startDate = new Date(startDate.replace(/-/g, "/"));
var endDate = "", noOfDaysToAdd = 13, count = 0;
while(count < noOfDaysToAdd){
    endDate = new Date(startDate.setDate(startDate.getDate() + 1));
    if(endDate.getDay() != 0 && endDate.getDay() != 6){
       //Date.getDay() gives weekday starting from 0(Sunday) to 6(Saturday)
alert(endDate);//You can format this date as per your requirement

Working Demo

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download