Skip to content

Instantly share code, notes, and snippets.

@romuleald
Created December 8, 2015 11:00
Show Gist options
  • Save romuleald/2fb63e6426faffb7abfa to your computer and use it in GitHub Desktop.
Save romuleald/2fb63e6426faffb7abfa to your computer and use it in GitHub Desktop.
Get day in a week
/**
*
* @param date Date
* @param dayOfWeek {Number} between 1 (monday) to 7 (sunday)
*/
var getDayOfWeek = function (date, dayOfWeek) {
if(dayOfWeek > 7 || dayOfWeek < 1){
console.warn('dayOfWeek is out of range (1-7), was:', dayOfWeek);
}
var _date = new Date(date);
_date.setDate(_date.getDate() - (_date.getDay() || 7) + dayOfWeek);
return _date;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment