Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda