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

129
Views
Determine which Friday of the month the date is

Given a date like April 22, 2022 how can we accurately determine which Friday of that Month it is. In this case it is the 4th Friday.

I have tried all combinations of adding the week day (0-6, so 5) plus the current day, dividing things by 7, using % because it seems cool, etc. At this point I am stumped.

I am using the Luxon library, but also have access to native JS and dayjs

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

0

Try this out:

function getFriday(day, month, year){
    
    date = new Date(year, month - 1, day)

    if (date.getDay() === 5){
        return Math.ceil(day / 7)
    } else{
        return "Date is not a Friday"
    }
}

console.log(getFriday(21, 1, 2022)) // 3
console.log(getFriday(4, 2, 2022)) // 1
console.log(getFriday(22, 4, 2022)) // 4
console.log(getFriday(15, 5, 2022)) // Date is not a Friday

It creates a date object from the function arguments, checks if the date is a Friday, then calculates which Friday it is. If the date is not a Friday, it returns "Date is not a Friday", though this could be removed to return null.

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!