Skip to content

Instantly share code, notes, and snippets.

@psdtohtml5
Created October 15, 2013 23:58
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save psdtohtml5/7000529 to your computer and use it in GitHub Desktop.
Save psdtohtml5/7000529 to your computer and use it in GitHub Desktop.
JavaScript : Add Business days to a date
// https://github.com/lsmith/addBusinessDays/blob/master/addBusinessDays.js
// var d = new Date();
// addBusinessDays(d, numberOfDays);
function addBusinessDays(d,n) {
d = new Date(d.getTime());
var day = d.getDay();
d.setDate(d.getDate() + n + (day === 6 ? 2 : +!day) + (Math.floor((n - 1 + (day % 6 || 1)) / 5) * 2));
return d;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment