Enumeration of dates between 'startdate' and 'enddate' using Custom function

in #spreadsheet6 years ago

frequently working schedule

we need to view dates between startdate and enddate.

1.jpg
[date type data]

2.jpg
[formular]

we can extract dates from working duration without adding any repeated codes.

[script]

function dtr( formula ){
if (typeof formula.map === "function"){
return formula.map(dtr);
}else if(formula){
return WriteTermDates(formula);
}
}

function WriteTermDates(d) {

var ss1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SHEET");

var testDate = new Date("1900/1/1");
var startDate = new Date(testDate.getDate()+parseInt(d.substring(0,5)-25569)24 * 60 * 60 * 1000);
var endDate = new Date(testDate.getDate()+parseInt(d.substring(5,10)-25569)
24 * 60 * 60 * 1000);

var values = "";

while(startDate.getDate() <= endDate.getDate()) {

//   Logger.log(Utilities.formatDate(startDate, "GMT", "MM-dd"));

values += Utilities.formatDate(startDate, "GMT", "MM-dd") + ", ";

startDate.setDate(startDate.getDate() + 1);

}
return values;
}