Last active
March 17, 2017 13:03
-
-
Save dbilovd/27c09fb96820879163ce4865cf337f41 to your computer and use it in GitHub Desktop.
Get date of start of week
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 startOfWeek (weekStart) { | |
var today = new Date(); | |
var todayInWeek = today.getDay(); | |
var todayDate = today.getDate(); | |
var startOfWeekDate = (weekStart == "m") ? | |
todayDate - (todayInWeek - 1) : todayDate - todayInWeek; | |
var startOfWeek = new Date(); | |
startOfWeek.setDate(startOfWeekDate); | |
return startOfWeek; | |
} | |
console.log(startOfWeek("s")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment