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

273
Views
How to use this JS function in Google Sheets? Using cell values in var and loop

So, I have this one function that calculates the number of Thursdays between two dates:

var startDate = new Date('2021/8/16');
var endDate = new Date('2022/3/15');

function THURSDAYS( days, d0, d1 ) {
  var ndays = 1 + Math.round((d1-d0)/(24*3600*1000));
  var sum = function(a,b) {
    return a + Math.floor( (ndays+(d0.getDay()+6-b) % 7 ) / 7 ); };
  return days.reduce(sum,0);
}

return(THURSDAYS([3],new Date(startDate),new Date(endDate)));

enter image description here

And I'm trying to use it as a custom function in Google Spreadsheet like here where it would return the sum/total of Thursdays found on each line. So I need to use cell values in startDate and enDate, then create a loop... Still learning so I guess I get easily fried up LOL

Anyways, thank you for any help you can give!

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

0

You don't need a custom function. Try

=SUMPRODUCT(N(WEEKDAY(ROW(INDIRECT( A2 &":"& B2));2)=4))
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!