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

118
Vistas
Snowflake Javascript to count between two element in a array

I have an array with dates in ascending order, I am trying to create a Snowflake UDF to count the array element between two dates.

The function should get the two days and tell us the count between the two days.

    create or replace function workdays_between(date1 String, date2 String)
 RETURNS double
  LANGUAGE JAVASCRIPT
  as 
  $$
  var DATE1 = DATE1
  var DATE2 = DATE2
  var count = 1
  var i = 1
  a = ["2017-01-01","2017-01-02","2017-01-03","2017-01-06","2017-01-09","2017-01-10"]
  if (DATE1 < DATE2) {
    for (i=1;a[i]<=DATE2;i++) {
        if (a[i] >= DATE1) {
         count = count + 1;
         }
      }
  }
    else
    {
        for (i=1;a[i]<=DATE1;i++) {
        if (a[i] >= DATE2) {
         count = count + 1;
        }
        }
        count = count * -1;
  }
     return count;
  $$

But I am not getting the desired output, please help.

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

0

the problem was with the case on DATE1 and DATE2, I gave in lower case inside the program, it worked after making it to upper case.

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