I like to have script that lists the date from start to enddate and put it in sheet2. When a new end and startdate gets added, the script adds dates automatic. Format for the date dd-mm-yy
I hope you can help, I've searched many script that i could not use. Thanks.
Sheet1
A B
startDate endDate
5-4-13 12-4-13
19-4-13 26-4-13
Result in Sheet2
A
Dates
5-4-13
6-4-13
7-4-13
8-4-13
9-4-13
10-4-13
11-4-13
12-4-13
19-4-13
20-4-13
21-4-13
22-4-13
23-4-13
24-4-13
25-4-13
26-4-13 In column A
Thanks everybody for their replies. I already had googled a lot, and I have pasted something together dat almost works. The script does not print the last day and sometimes it starts with the day before the start date. Could it have someting to do with the date difficulties and setValue ?
function getDates() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var export = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2");
var startRow = 2; // First row of data to process
var numRows = sheet.getLastRow()-1; // Number of rows to process
// Fetch the range of cells A:B
var dataRange = sheet.getRange(startRow, 1, numRows, sheet.getLastColumn());
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i=0; i < data.length; i++) {
var row = data[i];
var startDate = row[0] //get start date
var endDate = row[1]; //get the end Date
endDate.setHours(0);
var e = Utilities.formatDate(endDate,'GMT+0100','d-M-yyyy');
//Logger.log(endDate+" "+e);
//Logger.log(date+" ");
startDate.setHours(0);
for (var k=0; k<9; k++) {
var date=new Date(startDate.getYear(),startDate.getMonth(),startDate.getDate() + k);
//Logger.log(d+" "+date);
var d = Utilities.formatDate(date,"GMT+0100","d-M-yyyy");
var last_row = export.getLastRow();
export.insertRowAfter(last_row);
var target_range = export.getRange("A"+(last_row + 1));
target_range.setValue(d);
if (e == d) break;
}
}
}
I've found a solution, but I do not think it is the best solution. I hope there is a better solution. so I have 11 hours added to the GMT time. And the output is OK
I have changed; var e = Utilities.formatDate(endDate,'GMT+0100','d-M-yyyy'); to; var e = Utilities.formatDate(endDate,'GMT+1200','d-M-yyyy');
and; var d = Utilities.formatDate(date,"GMT+0100","d-M-yyyy"); to; var d = Utilities.formatDate(date,"GMT+1200","d-M-yyyy");