Created
December 19, 2017 20:05
-
-
Save codenamejason/e3e4dbce072c82b765943e9e6a754216 to your computer and use it in GitHub Desktop.
Gets the beginning of the week using the current date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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