title: Older date in Spreadsheets Google Script
body: <p>I am trying to get information of newly created files in a G drive folder. Everytime I run my program the output should refer only to new files in the folder. The D column will contain the creation dates. So I read the last value of the D column, let's call it DX; DX would have the creation date of the newest file (because I sorted them in the last line of the program). Then I compare DX to the creation dates of all the files in my folder. Only the files.creationDate &gt; DX are the ones I need. I've managed to come up with:</p>
  <pre><code>  var folder = DriveApp.getFolderById('1gsXZWKSPxAsFiyuaMMNTkg6n_4p9HOeU');  
    var contents = folder.getFiles();
  //get value of D2
    var control_cell = SpreadsheetApp.getActiveSheet().getRange('D2');
  //get last non blank value in the D column and assign it to variable lastTimeCreated
    var values = SpreadsheetApp.getActiveSheet().getRange('D:D').getValues().flat().filter(String);
    var [lastTimeCreated] = values.slice(-1)
  //If D2 is empty assign an old date to lastTimeCreated
    if (control_cell.isBlank()){
      lastTimeCreated = '1/10/2020 12:00:00'
    }
    
    var varFile;
    var varTime;
    var dataRows = [];
    let i = 0;
  
    while(contents.hasNext()){
      varFile = contents.next();
      varTime = varFile.getDateCreated().toLocaleString();
  
      if(new Date(varTime).getTime() &gt;= new Date(lastTimeCreated).getTime() &amp;&amp; varOwner.includes(actualSheetName)){
        dataRows[i] = [varTime];
        i++;
      }
      else{
        continue
      }
    }
    const sortedRows = dataRows.sort((a, b) =&gt; new Date(a[3]) - new Date(b[3]));
  </code></pre>
  <p>The problem is the last <code>if</code> with the <code>new Date(varTime).getTime() &gt;= new Date(lastTimeCreated).getTime()</code> statement. I think <code>lastTimeCreated</code> can't be interpreted as a Date and as a result they can't be compared. I know <code>varTime</code> is not the problem because the last line of this program works perfectly. Maybe the problem is the format date of both dates (?). I've also tried with <code>Date.parse()</code> for both variables but it hasn't worked.</p>
  <p>My spreadsheet looks like this:
  <a href="https://i.stack.imgur.com/QxGuG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QxGuG.png" alt="Sample of the spreadsheet mentioned in the question" /></a></p>
  <p>Any help is widely appreciated.</p>
  <p><strong>Edit</strong>
  The date format is this: 1/10/2020 12:00:00</p>
  <p><strong>Edit 2</strong>
  As suggested, provided more information and added some more code.</p>