I have a google spreadsheet and want to use Google Apps Script to activate cell B1 in the first sheet (currently formatted as a date - 1/27/2014) and change it to that date plus 7 days (2/3/2014). I am pretty new to Google Apps Script and have only successfully written a couple other functions. What I was thinking so far was:
function changeDate() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var b1_date = sheet.getRange("B1").getValue();
//...
}
function changeDate()
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("B1");
var oldDate = cell.getValue().getTime(); //milliseconds from 1/1/1970
var newDate = new Date();
newDate.setTime(oldDate + (7*24*60*60*1000)); //add milliseconds in 7 days
cell.setValue(newDate);
}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With