Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

343
Vistas
How to compare dates with day, month and year only

I'm trying to go over a column that has some random dates and find todays date then save that row in a variable. I honestly wrote the code to do that, but for some reason its not working with which I don't know why.

This is my code.

 const ss = SpreadsheetApp.openByUrl(THIS).getSheetByName("Daily PO Dashboard");
  let birthday = new Date(2022, 1, 21,3,00,00)    
  for(var row=0; row<data.length; row++){
  if(data[row][16]==birthday){
    Logger.log(" I'm in!")
      ss.getRange('B3:AA').setValue(data[row]);
  }
  }
  var checkBox = ss.getRange('A3:A').insertCheckboxes();

I also tried to set the birthday as

var birthday = new Date();

but nothing is working with me.

This is what I'm comparing with.

[this is column 16 and each row is row

Note: it never goes in the if statement

this is data[row][16] when I logger.log it.

enter image description here

Note: there are more but they are all either dates or null

Also I logger.log(typeof data[row][17]), and i got a string.

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Using strings and Utilities.formatDate() seems kind of brute force to me. If I have to compare dates I remove the time and then use valueOf() to compare dates.

function dummy() {
  try {
    var d1 = new Date();
    Utilities.sleep(100);
    var d2 = new Date();
    console.log(d1);
    console.log(d2);  // Notice in console log they look alike but are different by 100 msec.
    console.log( d1.valueOf() === d2.valueOf() );
    function removeTime(date) {
      return new Date(date.getFullYear(),date.getMonth(),date.getDate());
    }
    d1 = removeTime(d1);
    d2 = removeTime(d2);
    console.log(d1);
    console.log(d2);
    console.log( d1.valueOf() === d2.valueOf() );
  }
  catch(err) {
    console.log(err);
  }
}

2:46:07 PM  Notice  Execution started
2:46:07 PM  Info    Mon Feb 21 2022 17:46:07 GMT-0500 (Eastern Standard Time)
2:46:07 PM  Info    Mon Feb 21 2022 17:46:07 GMT-0500 (Eastern Standard Time)
2:46:07 PM  Info    false
2:46:07 PM  Info    Mon Feb 21 2022 00:00:00 GMT-0500 (Eastern Standard Time)
2:46:07 PM  Info    Mon Feb 21 2022 00:00:00 GMT-0500 (Eastern Standard Time)
2:46:07 PM  Info    true
2:46:07 PM  Notice  Execution completed
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda