0

I need to check if a date (in cell D2) already exists in a range (from D3). Here is the code :

var range = ss.getRange(3,4,ss.getMaxRows(),1).getValues();
var cellLastDate = ss.getRange("D2").getValues()[0];
var DateExists = range.some(function(row){
return row[0] === cellLastDate;
});

And the logs :

Logger.log(ss.getRange(3,4,ss.getMaxRows(),1).getValues());
...
[[Wed Sep 28 00:00:00 GMT+02:00 2022], [Wed Sep 28 00:00:00 GMT+02:00 2022], [Wed Sep 28 00:00:00 GMT+02:00 2022], [Wed Sep 28 00:00:00 GMT+02:00 2022], [Wed Sep 28 00:00:00 GMT+02:00 2022], [Mon Sep 26 00:00:00 GMT+02:00 2022], [Sat Sep 24 00:00:00 GMT+02:00 2022], [Wed Sep 21 00:00:00 GMT+02:00 2022], [Mon Sep 19 00:00:00 GMT+02:00 2022], [Sat Sep 17 00:00:00 GMT+02:00 2022], [Fri Sep 16 00:00:00 GMT+
Logger.log(ss.getRange("D2").getValues()[0]);
...
[Wed Sep 28 00:00:00 GMT+02:00 2022]

The date already exists in the range but my variable DateExists returns false in the console and I do not understand why.

Twilight
  • 1,399
  • 2
  • 11
Sébastien
  • 11
  • 1

0 Answers0