0

So basically, I need a dropdown to be generated with date ranges for the list of weeks between two years. So, for example, if the years are 2012 and 2014, it'll generate a list of weeks such as:

1/1/12-1/7/12

1/8/12-1/14/12

etc.

Going on until the last week of 2014. If there's not enough to generate a week there, it'll simply go until 12/31/14. This is to be used to generate weekly reports via MySQL, but the back-end is already written. I just need to build the interface.

Now, before you ask, I'm not using JQuery. So JQuery solutions are appreciated, but not useful. Sorry!

  • 1
    Why don't you generate these server side? – Derek Jun 21 '13 at 20:23
  • Well, a multitude of different report types and configuration options have to be generated. The overall project is more complex than that (graphing over canvas, etc) and it'd make little sense to have one small portion of it server-side when the rest is already JavaScript-heavy. –  Jun 21 '13 at 20:26

1 Answers1

0

Figured it out. Turns out I was just being dense and lazy.

Here, for the future, is the general logic:

var enddate, finaldate, startyear, endyear, i;
startyear = 何々;
endyear = 何々;
enddate = new Date(endyear, 11, 31)
finaldate = new Date(enddate)
enddate.setDate(enddate.getDate() + 6)
for (i = new Date(startyear, 0, 1); i <= enddate; i.setDate(i.getDate()+6)) {
    if (i > finaldate) {
        console.log(finaldate);
    } else {
        console.log(i);
    }
}
  • I edited my answer to include pseudocode for that same algorithm. but when I was done editing you had already posted with real code. – Jacob Jun 21 '13 at 21:07