So I have a sheet where in column A I have multiple rows with dates.
I am trying this to get the dates:
cells = sheet.getRange("A5:A").getDisplayValues();
It displays something like this:
[
[ '7/30/2020 1:00:00' ],
[ '7/31/2020 19:00:00' ],
[ '8/1/2020 1:00:00' ],
[ '8/2/2020 19:00:00' ],
[ '7/30/2021 1:00:00' ],
[ '7/31/2021 19:00:00' ],
[ '8/1/2021 1:00:00' ],
[ '8/2/2021 19:00:00' ]
]
I need a way to get an array with the row numbers where the date is August 2020 for example. In this case it would be rows 3 and 4. So like this:
[ 3, 4 ]
Please note the dates are using en_US date format. It would have to be a method that works even if locale is set for for ex. en_GB where the array of arrays with dates looks like this:
[
[ '30/07/2020 01:00:00' ],
[ '31/07/2020 19:00:00' ],
[ '01/08/2020 01:00:00' ],
[ '02/08/2020 19:00:00' ],
[ '30/07/2021 01:00:00' ],
[ '31/07/2021 19:00:00' ],
[ '01/08/2021 01:00:00' ],
[ '02/08/2021 19:00:00' ]
]
Is such a thing possible?
Best result so far I got was with this:
cells = sheet.getRange("A5:A").createTextFinder("MM/YYYY").findAll().map(x => x.getRow());
But maybe createTextFinder() is not the best way to do this? Also the above only works when date format is dd/MM/YYYY which for users from en_US won't work, and also for other areas as well, which separate the MM from the YYYY with d like in case of en_US is M/d/YYYY. Other locales also have the date format like YYYY/MM/d or even YYYY/dd/MM and so on.
In order to fix this I created a long list of switch statements with every possible locale which got big. And in cases like en_US, createTextFinder() won't work for combination of month and year separated by day: M/d/YYYY.
So maybe this question is 2 questions into one. First I asked how to filter array of arrays with dates, but maybe there is a better way of getting the row numbers with the desired dates without using getDisplayValues() which will output not an array of arrays but something else?
Then the second part asks how to search the supposed array, array of arrays or array of object etc, for the row numbers which have a date which combines a specific month and year, in my example August 2020, regardless of the locale and date format, either its en_US or en_GB or any other.
Here is my file: https://docs.google.com/spreadsheets/d/1ExXtmQ8nyuV1o_UtabVJ-TifIbORItFMWjtN6ZlruWc/edit?usp=sharing