Zubair
Zubair

Reputation: 65

Get particular days from date range using javascript

I will provide two dates, as a range e.g 5th Oct 2016 to 5th December 2016, And 5th Oct was Wednesday so return me all the Wednesdays till 5th December 2016.

How can this be possible using Javascript or AngularJS ?

Upvotes: 0

Views: 36

Answers (1)

marsze
marsze

Reputation: 17064

Though not completely sure what you want to do, I think this will give you enough to work with:

var startdate = new Date("2016-10-05");
var enddate = new Date("2016-12-05");
var wednesdays = [];
while (startdate <= enddate) {
    wednesdays.push(startdate);
    // add a week
    startdate = new Date(startdate.setDate(startdate.getDate() + 7));
}
console.log(wednesdays);

Upvotes: 1

Related Questions