简体   繁体   English

Google Scripts - 添加天数至今 -

[英]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)每个注册的联系人都会添加到相关的表格中,指明注册的日期和时间(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我想知道是否使用与发送表单相关的脚本,我们可以将此值添加到列 J:注册日期 + 7 天

在此处输入图片说明

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:使用Form Submit Trigger 来运行这个函数:

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.我认为没有必要在这里使用 Google Apps Script。 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.如果条件为假,则将日期增加 7 天。 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.这些是您可以通过将日期格式应用于列来正确显示的有效日期。

格式化前的日期

格式化后的日期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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