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

254
Vistas
¿Cómo comparar la marca de tiempo cuando parece que no puedo llevarlos a un formato común usando GAS?

Entonces, al enviar el formulario, obtuve una marca de tiempo, que se ve así: "values":["2/18/2022 14:11:25"]

Luego necesito compararlo con el de la hoja de cálculo, para poder establecer un número en una columna adyacente. Entonces, estoy usando el siguiente código, pero me encuentro con un error en ```Utilities.formatDate()````

El código:

 function onSubmit(e) { Logger.log("%s", JSON.stringify(e)); const timeStamp = e.values[0] const formRespSheet = e.source.getSheetByName('Form Responses 1') var maxNumber = Math.max.apply(null, formRespSheet.getRange(2, 14, formRespSheet.getLastRow(), 1).getValues()); maxNumber = maxNumber + 1 Utilities.sleep(1000);//Tried it const allTimeStamps = formRespSheet.getRange(2, 1, formRespSheet.getLastRow(), 1).getValues(); for (let a = 0; a < allTimeStamps.length; a++) { let sheetTimeStamp = allTimeStamps[a] sheetTimeStamp = Utilities.formatDate(sheetTimeStamp, Session.getTimeZone(), "MM/dd/yyyy HH:mm:ss") if (sheetTimeStamp.valueOf() == timeStamp.valueOf()) { const row = a + 1 formRespSheet.getRange(row, 14).setValue(maxNumber) } } }

El error dice:

 The parameters (number[],String,String) don't match the method signature for Utilities.formatDate.

Gracias por tu ayuda.

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

0

La hoja de cálculo de Google tiene un objeto Fecha que funciona muy bien como comparación. Siempre, y no entiendo por qué todos no lo hacen, establezco el formato de número de una celda o celdas en Fecha. De esa manera puedo comparar fechas, restar fechas, etc. etc. Ahora, sé que el tiempo interes pero una función simple puede aliviar ese problema, tengo una hoja de cálculo que tiene dos Fechas que tienen la misma fecha pero tienen diferentes tiempos. Así puedo comparar si son el mismo día.

 function test() { try { var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2"); var range = sheet.getRange("B1:B2"); var values = range.getValues(); function removeTime( value ) { var temp = value[0]; value[0] = new Date(temp.getFullYear(),temp.getMonth(),temp.getDate()); }; console.log( new Date(values[0][0]) ); console.log( new Date(values[1][0]) ); console.log(values[0][0].valueOf() === values[1][0].valueOf()); values.forEach( removeTime ); console.log( new Date(values[0][0]) ); console.log( new Date(values[1][0]) ); console.log(values[0][0].valueOf() === values[1][0].valueOf()); } catch(err) { console.log(err); } } 9:15:47 AM Notice Execution started 9:15:47 AM Info Fri Feb 18 2022 11:53:45 GMT-0500 (Eastern Standard Time) 9:15:47 AM Info Fri Feb 18 2022 11:54:16 GMT-0500 (Eastern Standard Time) 9:15:47 AM Info false 9:15:47 AM Info Fri Feb 18 2022 00:00:00 GMT-0500 (Eastern Standard Time) 9:15:47 AM Info Fri Feb 18 2022 00:00:00 GMT-0500 (Eastern Standard Time) 9:15:47 AM Info true 9:15:48 AM Notice Execution completed
about 4 years ago · Juan Pablo Isaza Denunciar

0

sheetTimeStamp = Utilities.formatDate(sheetTimeStamp, Session.getTimeZone(), "MM/dd/yyyy HH:mm:ss")

cambie a:

 sheetTimeStamp = Utilities.formatDate(new Date(sheetTimeStamp), Session.getTimeZone(), "MM/dd/yyyy HH:mm:ss")

deberia de funcionar

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