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

253
Views
¿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 answers
Answer question

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 Report

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 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!