Reputation:
I'm trying to create a code that gets the sheet model(https://docs.google.com/spreadsheets/d/1K2_T8Gd6O-xbMff1B3trZrq8lF10DyRffd8jF4XQkqk/edit?usp=sharing), copy it, create a new sheet and change the date in range "I2" adding 7 days after in the new sheet. Example = (07/05/2020) to (14/05/2020). And also It does a loop that every time it creates a new sheet with the date 1 week later, Somebody could help me?
function CopyMinute(){
var minuteSheet = SpreadsheetApp.openById('id-example')
var getSheet = minuteSheet.getActiveSheet()
var newsheet = getSheet.copyTo(minuteSheet)
var getDate = newsheet.getRange("I2")
var date = getDate.getValue()
var setSevenDaysAfter = getDate.setValue(date+"+7")
Logger.log(date)
}
Upvotes: 0
Views: 48
Reputation: 377
You need to convert the week, i.e. seven days, to milliseconds and then add it to your date in milliseconds.
var date = getDate.getValue()
var weekInMs = 1000 * 60 * 60 * 24 * 7;
var nextWeek = new Date(date.getTime() + weekInMs);
Here is the official documentation.
Upvotes: 2