Question

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!

Was it helpful?

Solution

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);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top