Google Sheets Script: Find First Date Earlier Than Target Date

Using GoogleFinance to load historical data into a sheet, I'm trying to find the last Trading Date for a given year and month in a script function. So I use a for loop, going backwards, to compare dates and find the first date that is earlier than the first day of the month following the target month.

But I have an error in the way I'm checking for this. A check code segment is:

  if ( aSource[j][0] < analysisDate ) { rv = 'NO'; } else { rv = 'YES'; }
  ui.alert('SourceDate    =' + aSource[j][0] +
          '\nAnalysisDate =' + analysisDate +
          '\nIs SourceDate before AnalysisDate:  ' + rv);

The result is: enter image description here

I must be using the operator incorrectly, but I haven't been able to find an example that shows how to do it, so any advice would be appreciated!

Read more here:

Content Attribution

This content was originally published by maxhugen at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: