title: Google Script to delete row if date in certain cell is smaller than current date
body: <p>I want a Google Script which checks once a day on my spreadsheet and copies the values to another sheet and than deletes all the rows if the date in that cell is small than the current.</p>
  
  <p>The file looks like this:
  <a href="https://i.stack.imgur.com/L2syJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L2syJ.png" alt="enter image description here"></a></p>
  
  <p>And this is what I wrote so far:</p>
  
  <pre><code>function DeleteIfDateIsToSmall(event) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var s = event.source.getActiveSheet();
    var r = event.source.getActiveRange();
    var today = new Date();
    var today2 = Utilities.formatDate(today,'GMT+0200','dd.MM.yyyy');
    var startRow = 2;  // First row of data to process
    var numRows = sheet.getLastRow()-1
  
    for (var i=2; i &lt; numRows; i++) {
      var DateCell  = s.getRange(i, 13);  
      var sheetDate = DateCell.getValue()
      var sheetDate2 = Utilities.formatDate(sheetDate,'GMT+0200','dd.MM.yyyy');
      var row = i;
      var numColumns = s.getLastColumn();
      var targetSheet = ss.getSheetByName("Ended or Deleted");
      var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
  
      if (s.getName() == "Start" &amp;&amp; sheetDate != 0 &amp;&amp; sheetDate != "" &amp;&amp; today2.valueOf() &gt; sheetDate2.valueOf()){
        s.getRange(row, 1, 1, numColumns).moveTo(target);
        s.deleteRow(row); 
      }
    }
  }
  </code></pre>
  
  <p>It doesn't seem to work, please help.</p>