Created
August 6, 2020 16:05
-
-
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.
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 = 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