Skip to content

Instantly share code, notes, and snippets.

@nikita8
Created May 9, 2013 16:09
Show Gist options
  • Save nikita8/5548444 to your computer and use it in GitHub Desktop.
Save nikita8/5548444 to your computer and use it in GitHub Desktop.
last monday from 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());
Date.today().previous().monday()
Date.parse('last monday');
function nextSession(date) {
var ret = new Date(date||new Date());
ret.setDate(ret.getDate() + (3 - 1 - ret.getDay() + 7) % 7 + 1);
return ret;
}
today=new Date()
thisDay=today.getDay()
http://stackoverflow.com/questions/5210376/get-first-and-last-day-of-the-week-in-javascript
http://stackoverflow.com/questions/3638906/get-date-of-specific-day-of-the-week-in-javascript
http://stackoverflow.com/questions/5210376/get-first-and-last-day-of-the-week-in-javascript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment