Skip to content

Instantly share code, notes, and snippets.

@timbillstrom
Created August 6, 2020 16:05
Show Gist options
  • Save timbillstrom/917b34e72c54996f6cd51b4ac3ba7aa8 to your computer and use it in GitHub Desktop.
Save timbillstrom/917b34e72c54996f6cd51b4ac3ba7aa8 to your computer and use it in GitHub Desktop.
Get the date for Monday and Friday of the current week, with JS.
function getMonday() {
d = new Date();
var day = d.getDay(),
diff = d.getDate() - day + (day == 0 ? -6 : 1);
return new Date(d.setDate(diff));
}
function getFriday() {
let monday = getMonday();
return new Date(monday.setDate(monday.getDate() + 4));
}
console.log(getMonday());
console.log(getFriday());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment