javascript - Future Date Calculator -


i have following script when used, allows user see future date, while excluding weekends. problem i've encountered though if current day friday, , set future date 3 days counts saturday , sunday working days. i'm hoping 1 of may able i'm not great @ javascript.

the correct example be: if today = friday 3 working days wednesday (not monday script calculates it).

any ideas?

          var mydelayindays = 3;            mydate=new date();           mydate.setdate(mydate.getdate()+mydelayindays);            if(mydate.getday() == 0){//sunday             mydate.setdate(mydate.getdate() + 2);//tuesday           } else if(mydate.getday() == 6){//saturday             mydate.setdate(mydate.getdate() + 2);//monday           }            document.write('' + mydate.tolocaledatestring('en-gb')); 

any great. thanks

try code changing date , days add, custom loop used skip sat , sun

function adddates(startdate,noofdaystoadd){    var 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 0(sunday) 6(saturday)         count++;      }    }    return startdate;  }      var today = new date();  var daystoadd = 3;  alert(adddates(today,daystoadd));


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -