Skip to content

Instantly share code, notes, and snippets.

@mazipan
Forked from psdtohtml5/snippet.js
Created January 23, 2018 03:22
Show Gist options
  • Save mazipan/b973e385c2e8e679801b2fb44c19a745 to your computer and use it in GitHub Desktop.
Save mazipan/b973e385c2e8e679801b2fb44c19a745 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