setting day of week in javascript
how do you set a day in javascript?
You mean, in the current week? When does a week start?
Assuming it starts on Sunday (as in getDay
: 0 - Sunday, 1 - Monday, etc), this will work:
var date, daytoset; // given: a Date object and a integer representing the week day
var currentDay = date.getDay();
var distance = daytoset - currentDay;
date.setDate(date.getDate() + distance);
To set the date to a weekday in the next 7 days, use this:
var distance = (daytoset + 7 - currentDay) % 7;