Simple “Days Iteration” Algorithm with a twist
Yet another one of this date iterations algorithms, due to the particulars of the script I was running I had to redo the date iteration to start on one date and iterate through all the days till another one. This is the new version, (that I’m blogging for not having to go through this again in the future):
begA = 2001;
begM = 3;
begD = 1;
endA = 2007;
endM = 1;
endD = 1;
itA = begA;
itM = begM;
itD = begD;
while( ((itA!=endA) || (itM!=endM) || (itD!=endD)) ) {
//Print
document.write(itA + '-' + itM + '-' + itD + '');
if(itM==12 && itD==31) {
//End of Year
itA++;
itM=01;
itD=01;
} else if(
//End of Month
( (itM==1 || itM==3 || itM==5 || itM==7 || itM==8 || itM==10 ) && itD==31)
//Months with 31 days
|| ( (itM==4 || itM==6 || itM==9 || itM==11 ) && itD==30)
//Months with 30 days
|| (itM==2 && itD==28 && (itA%4!=0))
//February not leap
|| (itM==2 && itD==29 && (itA%4==0))
//February leap
) {
itM++;
itD=01;
} else {
itD++;
}
}


