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;

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)