1

I have been able to write my code based on answers to other questions on here however, I am stuck. I am new to coding and teaching myself as I go. I have a spreadsheet that is filled when a form is submitted. There is a date that populates into column B (date of incident). I want to add 60 days to that date for a due date. I have been able to add the 60 days but for only one cell.

I have added a menu in the Ui that has a button to run the function and it works but for that cell. I want to be able to be on the cell that I want the due date added to and when I select it in the Ui have it fill in the date. I am guessing it has something to do with .getActiveCell but I am stuck.

function setDuedate()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('2020');
  var dateOfincident = new Date(sheet.getRange('B3').getValue()).getTime();
  var dayInMs = 24*60*60*1000

  var due = dateOfincident + (60*dayInMs)

  sheet.getRange('L3').setValue(new Date(due));
pczeus
  • 7,709
  • 4
  • 36
  • 51
Eric
  • 11
  • 1
  • You're asking a JavaScript question, but you've tagged it Java. Java is not JavaScript. – MarsAtomic May 06 '20 at 23:04
  • This doesn't look like Java. `function` is not a valid Java keyword. Is your program perhaps in Javascript? If it is Java, don't use Date. It's use is deprecated. – David Conrad May 06 '20 at 23:04
  • 1
    If you are using Javascript, you might want to look at moment.js. It has useful functions like `moment("2020-06-20", "YYYY-MM-DD").add(60, 'days');` – David Conrad May 06 '20 at 23:09
  • IMO you'll find a good answer here: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript/3674550 – Ictus May 07 '20 at 12:43
  • Does this answer your question? [Incrementing a date in JavaScript](https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript) – Ictus May 07 '20 at 12:45

0 Answers0