1

Attempting to filter an array named allAppointments by condition of value[3] being equal to var date. As you can see in the console, both allAppointments[75][3] and var date are equal to Wed Jul 21 2021 00:00:00 GMT-0400 (Eastern Daylight Time)

Yet, the statement declaring them equal proves false, with or without the use of new Date (), and subsequently the filter doesn't admit allAppointments[75], or any, producing an empty array.

Any idea what's going wrong here? Need I mention, my first attempt was just plain allAppointments[75][3] == date, and that didn't work, either.

var allAppointments = ss.getSheetByName('appts').getDataRange().getValues();
console.log (allAppointments[75]); 
console.log (allAppointments[75][3]); 
console.log (new Date(date)); 
console.log (allAppointments[75][3] == new Date(date)) ;
console.log (new Date(allAppointments[75][3]) == new Date(date)) 

var appointments = allAppointments.filter(function(value){return value[3] == new Date(date)}) ; 
console.log (appointments);


12:05:09 AM Info    [ 'a^36',
  '461.1 § massage gig',
  60,
  Wed Jul 21 2021 00:00:00 GMT-0400 (Eastern Daylight Time),
  Sat Dec 30 1899 12:00:00 GMT-0500 (Eastern Standard Time),
  'S. Ong #4-2' ]
12:05:09 AM Info    Wed Jul 21 2021 00:00:00 GMT-0400 (Eastern Daylight Time)
12:05:09 AM Info    Wed Jul 21 2021 00:00:00 GMT-0400 (Eastern Daylight Time)
12:05:09 AM Info    false
12:05:09 AM Info    false
12:05:09 AM Info    []
  • 1
    For testing equivalency with dates use valueOf() or getTime() methods – Cooper Jul 17 '21 at 14:13
  • Thank you! I have amended to the code to `var appointments = allAppointments.filter(function(value){return new Date(value[3]).getDate() == new Date(date).getDate() })` Works perfectly now! – Atiq Zabinski Jul 17 '21 at 15:29

0 Answers0