-1

I have tried to make the dates below dynamic by using today() plus minus 7 but that's not working, how to make this dynamic so I don't have to change the date every week

I am looking to keep it within a range of 14 days

function getEvents() {
  const ss = SpreadsheetApp.openById("ID").getSheetByName("Name");
  var lr = ss.getLastRow();
  if (lr > 0) {
  ss.getRange(2, 1, lr - 1, 6).clearContent();
}
  const ids = ['calendarid@google.com'];//cal ids
  ids.forEach(id => {
    let cal = CalendarApp.getCalendarById(id);
    let events = cal.getEvents(new Date("5/9/2022 12:00 AM"), new Date("5/13/2022 11:59 PM"));
      for (var i = 0; i < events.length; i++) {
      var title = events[i].getTitle();
      var sd = events[i].getStartTime();
      var ed = events[i].getEndTime();
      var loc = events[i].getLocation();
      var des = events[i].getDescription();
      ss.appendRow([sd,ed,title,loc,des,id])
    }
  })
}
Rubén
  • 29,320
  • 9
  • 61
  • 145
Rahi
  • 19
  • 7
  • Google Apps Script / JavaScript hasn't a built-in function named Today(), instead you could use `new Date()`. See the answers to "original question" to see it's use on a Google Apps Script / Google Calendar context. A more general question is https://stackoverflow.com/q/24894648/1595451 – Rubén May 20 '22 at 17:11
  • @Rubén so should I just add new Date() - 7 – Rahi May 21 '22 at 04:03

0 Answers0