-1

Hi im currently trying to compare an array of data using the ArrayLib but it is unable to match any of my dates and thus passing all of the data sets instead of just the ones between the date range. If there is a better way to achieve this im open to it [copy of my code that I am currently using ][1]: https://i.stack.imgur.com/Uj7Wo.png

EDIT: as requested a Google sheet of a sample data table im using: https://docs.google.com/spreadsheets/d/1whrB9O84i85grz6Av3EY-hnGGNvVG6ji_v5w7X_rMG0/edit?usp=sharing

Anarchyz
  • 3
  • 3
  • You should share your complete code for replication purposes. Please see https://stackoverflow.com/help/minimal-reproducible-example. Also, please share a sample sheet file with a few sample workable data (similar to your actual sheet file). – SputnikDrunk2 Jul 13 '21 at 17:01
  • Thank you, I went ahead and made a sample of the data – Anarchyz Jul 13 '21 at 17:14

1 Answers1

0

Instead of using a separate library to filter your multidimensional array by date, you can try this sample script below:

Sample script

function main() {
  var ssLc = SpreadsheetApp.getActive().getActiveSheet();
  var rangeLc = ssLc.getRange('A1:R15');
  var Lc = rangeLc.getValues();

  var startDate =  new Date('January 04, 2021 08:00:00'); //Used GMT time on my testing
  var endDate =  new Date('June 03, 2021 08:00:00'); //Used GMT time on my testing

  var sampleResult = filterByDate(Lc, startDate, endDate);

  for(x=0; x<sampleResult.length;x++){ //Sample loop to log the each filtered array data
    Logger.log(sampleResult[x]);
  }
}

function filterByDate(arrayData, startDate, endDate){
  var newArrayResult = [];
  for(index = 0; index < arrayData.length; index++){
    if(arrayData[index][0].getTime() >= startDate.getTime() && arrayData[index][0].getTime() <= endDate.getTime()){
      newArrayResult.push(arrayData[index]);
  }
 }
 return newArrayResult;
}

Sample Result:

Used your sample spreadsheet data:

enter image description here

Sample result by filtering data from January 04, 2021 to June 03, 2021

enter image description here

SputnikDrunk2
  • 3,398
  • 1
  • 5
  • 17
  • tried it and worked so much better, Thank you! – Anarchyz Jul 13 '21 at 19:50
  • @Anarchyz You're welcome. Consider accepting and upvoting my answer if you feel it was useful to you. Also, upvoting this answer will help other community members who are looking for the same answer to be suggested to your post. – SputnikDrunk2 Jul 13 '21 at 20:17