Google Apps Script - deleting a row if today's date is past input date -


i'd make script compares date within row today's date , delete row if today's date paste date row.

this current script:

    function deleterow1() { var sheet = spreadsheetapp.getactivesheet(); var startrow = 1;  // first row of data process var numrows = sheet.getlastrow()-1;   // number of rows process var datarange = sheet.getrange(startrow, 2, numrows); // fetch values each row in range. var data = datarange.getvalues();  (i=0;i<data.length;i++) {   var row = data[i];   var date = new date();   var sheetdate = new date(row);  var sdate = utilities.formatdate(date,'gmt+0200','yyyy:mm:dd')  var ssheetdate = utilities.formatdate(sheetdate,'gmt+0200', 'yyyy:mm:dd')         if (sdate > ssheetdate){           sheet.deleterow(i+2) //don't delete header } } } 

the ultimate goal compare dates in column c today's date , delete particular row if today's date greater.

right when run script, deletes rows, not rows earlier today's date.

the beginnings of script based off stackoverflow post

when start iteration top bottom deleting row in iteration alter offset (actual row number) of next rows

above problem can solved using start iteration bottom top.

for (i=data.length-1;i>=0;i--)  

here working code

function deleterow1()  {     var sheet = spreadsheetapp.getactivesheet();     var startrow = 2;  // first row of data process     var numrows = sheet.getlastrow()-1;   // number of rows process     var datarange = sheet.getrange(startrow, 2, numrows);     // fetch values each row in range.     var data = datarange.getvalues();      (i=data.length-1;i>=0;i--)      {           var row = data[i];           var date = new date();           var sheetdate = new date(row);           var sdate = utilities.formatdate(date,'gmt+0200','yyyy:mm:dd')           var ssheetdate = utilities.formatdate(sheetdate,'gmt+0200', 'yyyy:mm:dd')           if (sdate.valueof() > ssheetdate.valueof())           {                 sheet.deleterow(i+2) //don't delete header           }     }  } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -