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

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

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