Given two Date() objects, where one is less than the other, how do I loop every day between the dates?
for(loopDate = startDate; loopDate < endDate; loopDate += 1)
{
}
Would this sort of loop work? But how can I add one day to the loop counter?
Thanks!
Here simple working code, worked for me
Based on Jayarjo's answer:
Based on Tom Gullen´s answer.
Here's a way to do it by making use of the way adding one day causes the date to roll over to the next month if necessary, and without messing around with milliseconds. Daylight savings aren't an issue either.
Note that if you want to store the date, you'll need to make a new one (as above with
new Date(d)
), or else you'll end up with every stored date being the final value ofd
in the loop.