Skip to content

Instantly share code, notes, and snippets.

@codenamejason
Created December 19, 2017 20:05
Show Gist options
  • Save codenamejason/e3e4dbce072c82b765943e9e6a754216 to your computer and use it in GitHub Desktop.
Save codenamejason/e3e4dbce072c82b765943e9e6a754216 to your computer and use it in GitHub Desktop.
Gets the beginning of the week using the current date
function getMonday(d) {
d = new Date(d);
var day = d.getDay(),
diff = d.getDate() - day + (day == 0 ? -6:1); // adjust when day is sunday
return new Date(d.setDate(diff));
}
getMonday(new Date()); // Mon Nov 08 2010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment