I am trying to make a for loop with dates but it isn't going as planned. What I am trying to do is input startdate in cell A1 and enddate in cell B1. Then a for loop which runs: if startdate is less then enddate, put date in cell A2 and proceed to next column. The only thing I am stuck with is how to add one day to a date.
See code below:
function test()
{
var app = SpreadsheetApp;
var ss = app.getActive();
var sheet = ss.getActiveSheet();
var start = sheet.getRange("A1").getValue();
var end = sheet.getRange("B1").getValue();
var day = 3600*24*1000;
var diff = Math.floor((end-start)/day);
var column = 1;
for(var i=0;i<=diff;i++)
{
sheet.getRange(2, column).setValue(start+i*day);
column++;
}
}
Can someone explain to me why it doesn't work. Thanks a lot