Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
Google Aps Scripts: establezca un valor si la entrada no está en la fila

Estoy tratando de establecer un valor de entrada si este valor no está en una fila. Puedo obtener los valores de la fila y también establecer el valor.

Mi problema aparece cuando pregunté si la entrada está en la fila. Este es mi guion:

 //Auxiliar Funtion function is_in_array(array,value) { is_in = false Logger.log('This is the value: ' + value) for (i = 0; i < array.length; i++) { Logger.log('This is i: ' + array[i]) if (value == array[i]) { is_in=true; Logger.log('I was here!') } } return is_in } //Main function rm(){ var ss = SpreadsheetApp.getActiveSpreadsheet(); var ws = ss.getActiveSheet(); var fecha = ws.getRange(5,9).getValue(); //Reviso si existe la fecha ws = ss.getSheetByName(tipo); numCols = ws.getLastColumn(); fechas = ws.getRange(1,4,1,numCols).getValues()[0]; Logger.log('Fecha :' + fecha); Logger.log('Fechas: ' + fechas); is_in_result = is_in_array(fechas, fecha) Logger.log('Functions result: ' + is_in_result) //Logger.log(ArrayUtils.contains( fechas, fecha )) if (is_in_result==true) { Logger.log('If statement') return True } else { Logger.log('Else Statement') //Se añade la fecha ws.getRange(1,numCols+1).setValue(fecha) } }

Aquí está el registro:

 Registros de Cloud 9 ene 2022, 23:51:54 Información Fecha :Thu Sep 09 2021 03:00:00 GMT-0400 (hora de verano oriental) 9 ene 2022, 23:51:54 Información Fechas: Thu Sep 09 2021 03:00:00 GMT-0400 (hora de verano oriental),Fri Oct 15 2021 03:00:00 GMT-0400 (hora de verano oriental),Wed Dec 08 2021 03:00:00 GMT-0500 (hora estándar oriental),,, 9 ene 2022, 23:51:54 Información This is the value: Thu Sep 09 2021 03:00:00 GMT-0400 (hora de verano oriental) 9 ene 2022, 23:51:54 Información This is i: Thu Sep 09 2021 03:00:00 GMT-0400 (hora de verano oriental) 9 ene 2022, 23:51:54 Información This is i: Fri Oct 15 2021 03:00:00 GMT-0400 (hora de verano oriental) 9 ene 2022, 23:51:54 Información This is i: Wed Dec 08 2021 03:00:00 GMT-0500 (hora estándar oriental) 9 ene 2022, 23:51:54 Información This is i: 9 ene 2022, 23:51:54 Información This is i: 9 ene 2022, 23:51:54 Información This is i: 9 ene 2022, 23:51:54 Información Functions result: false 9 ene 2022, 23:51:54 Información Else Statement

Fecha está en Fechas, por lo que el resultado de la función debe ser verdadero, pero devuelve falso :(

¿Dónde está mi error? ¿O hay una manera más fácil de obtener el mismo resultado? A lo mejor no funciona porque estoy comparando dos fechas, no sé...

Algunas cosas están en español, lo siento.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No puede comparar diferentes objetos Date con == o === . Compárelos por sus milisegundos desde Unix Epoch con Date.getTime()

 var date1 = new Date( '2022-01-01' ); var date2 = new Date( '2022-01-01' ); console.log( 'date1 == date2: ' + ( date1 == date2 ) ); // false console.log( 'date1 === date2: ' + ( date1 === date2 ) ); // false console.log( 'date1.getTime() == date2.getTime(): ' + ( date1.getTime() == date2.getTime() ) ); // true

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!