0

I wanted help writing a function in Apps Script where I could input two dates and output an array of every date between the range.

  • Could you share more details about what you need to accomplish? The request is to vague to really give an appropriate answer as you may be looking for something really specific. Please visit [How to ask](https://stackoverflow.com/help/how-to-ask) to have some tips on how to write a question, so the community will be able to help you out in a better way – Gabriel Carballo Jul 05 '22 at 19:03

1 Answers1

0

A simple while loop should do the trick!

It'll loop through all dates between the start and the end date and store each day in between in an array.

To run it, simply call the function getDatesBetween and pass your dates as a parameter.

Try this:

function getDatesBetween(startDate, stopDate) {
    var dateArray = new Array();
    var currentDate = startDate;
    while (currentDate <= stopDate) {
        dateArray.push(new Date (currentDate));
        currentDate.setDate(currentDate.getDate() + 1);
    }
    return dateArray;
}

Reference taken from: Javascript - get array of dates between 2 dates

jeanjai77
  • 93
  • 6