0

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 ?

2
  • What have you tried so far? Do you use any other library for date manipulations - such as momentJS for example? Commented Oct 6, 2016 at 9:21
  • nopes not using any lib. I m using flex calendar lib for showing calendar Commented Oct 6, 2016 at 9:37

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! You are amazing man. Exactly what I was looking for :)
Only edit is, that we should use do-while loop because in while it is also exceeding one week from the end date given

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.