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

109
Views
JavaScript weekday list get

I need to create a JavaScript function for the below requirements. I need to get every week day date list. If you know nodeJs package tell me that. Thank you for your attention.

Example - 
 2022-01-03
 2022-01-04
 2022-01-05
 2022-01-06
 2022-01-07

 2022-01-10
 2022-01-11
 2022-01-12
 2022-01-13
 2022-01-14 
 ..........
 ..........
 until year-end

like this pattern (only Monday to Friday)

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

0

JavaScript's Date object overflows, so you can use:

for (i=1;i<366;i++) {
if (i%7==1 || i%7==2) continue;
const d = new Date(2022, 0, i);
document.write(d.toDateString(),'<br>');
}

You will need to watch for leap years, and recalculate which days are the weekend every year.

about 4 years ago · Juan Pablo Isaza Report

0

function getWeekDaysForYear(year) {
  const isLeap = year % 4 === 0;
  const numberOfDays = isLeap ? 366 : 365;
  let currentDate = new Date(Date.UTC(year, 0, 0, 0, 0, 0, 0));

  const weekDays = [];

  for(let i = 1; i <= numberOfDays; i++) {
    currentDate = new Date(currentDate.getTime() + 24 * 3600 * 1000);
    if (currentDate.getDay() === 0 || currentDate.getDay() === 6) {
      continue;
    }
    weekDays.push(currentDate.toISOString().split('T')[0]);
  }

  return weekDays;
}
console.log(getWeekDaysForYear(2022));

This is a simple function which returns all the weekdays for the specified year in an array.

about 4 years ago · Juan Pablo Isaza Report

0

Something like this

const endDate = new Date(2022,1,2);
const date = new Date(); //today

while (endDate > date) {
  const weekDay = date.getDay();
  if (weekDay != 6 && weekDay != 0) {
    let year = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(date);
    let month = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(date);
    let day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(date);
    console.log(`${year}-${month}-${day}`);
  }
  date.setDate(date.getDate() + 1);
}
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!