Link to home
Start Free TrialLog in
Avatar of teknovation
teknovation

asked on

Next Business Date using Javascript

Can someone tell me how this can be achieved and what is the syntax?
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<script>
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
// TEST FOR FRIDAY
var date = '2016-10-28';
var nbd = nextBusinessDay(date);
console.log("NBD for : " + date + " is [" + nbd + "] => " + days[nbd]);

//TEST FOR MONDAY
date = '2016-10-24';
nbd = nextBusinessDay(date)
console.log("NBD for : " + date + " is [" + nbd + "] => " + days[nbd]);

function nextBusinessDay(dt)
{
  var day = new Date (dt).getDay() + 1;
  day = (day > 5) ? 1 : day;
  return day;
}
</script>

Open in new window