Mauro Mancini
Mauro Mancini

Reputation: 53

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

enter image description here

Thank you all for your valuable help!

Upvotes: 1

Views: 2810

Answers (2)

Anton Dementiev
Anton Dementiev

Reputation: 5716

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.

Dates before formatting

Dates after formatting

Upvotes: 1

Jescanellas
Jescanellas

Reputation: 2608

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:

Upvotes: 1

Related Questions