简体   繁体   中英

Google Scripts - Adding Days to Date -

I ask for your help because I understand very little about programming! ;-(

I have a google form where customers sign up. Each contact who registers is added to the associated sheet indicating the date and time of registration (column A)

I would like to know if with a script, associated with sending the form, we could have this value added to column J: REGISTRATION DATE + 7 days

在此处输入图片说明

Thank you all for your valuable help!

You could try writing the date when submitting the form. Use the Form Submit Trigger to run this function:

function newRow() {

  var sprsheet = SpreadsheetApp.openById("your sheet Id");
  var sheet = sprsheet.getActiveSheet();

  var lastRow = sheet.getLastRow();

  //Gets the current date and adds 7 days to it
  var date = new Date();
  var value = new Date(date.setDate(date.getDate()+7));

  //"10" is the J column
  sheet.getRange(lastRow, 10).setValue(value);

  }

References:

I don't think there's a need to use Google Apps Script here. Just use the formulas to check for blanks in the date range

=ArrayFormula(IF(ISBLANK(A2:A),"",A2:A + 7));

The formula checks if the cell is blank and outputs an empty string if this condition evaluates to true. If the condition is false it increments the date by 7 days. Note that after applying the formula to the range, you may get what looks like numbers in results column (see below). These are valid dates that you can get to show correctly by applying date formatting to the column.

格式化前的日期

格式化后的日期

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM