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

170
Views
How to get first and last day of week from selected week/year using Moment.js?

I have a year and a week number - YYYY[W] <-> 2022[9].

I want to convert those using Moment.js in order to get the date range from that specific week.

  • The first day and the last day of that week is the best solution for my problem.
  • Or all the days from that specific week could also work.

So, something like :

function(year, week){
   *convert into date range*
   return dateRange
}

//Assuming , week 9 of 2022 I should return something like ['28/02/2022','6/03/2022'] which correspond to first and last day of that week

Looking into the docs at the moment, looking for a solution : https://momentjs.com/docs/#/get-set/week-year/

Any help would be welcome on this topic

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

0

Assuming the first day is Monday, here is your solution:

function calculateDateFromWeekNumAndYear(year, week) {
  const firstDate = moment().day('Monday').year(year).week(week).format('YYYY-MM-DD');
  const lastDate = moment(firstDate).add(6, 'days').format('YYYY-MM-DD');
  const dateRange = [firstDate, lastDate];
  return dateRange;
}
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!