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

118
Views
Create Date from string with week number in Javascript

I have a string like 2020-44 which contains year and number of the week in the year. Is it possible to create Date object from this string in some easy way? Javascripot is able to create dates from string like new Date('2020-12-24'). But I would like to use it with format 2020-44. Is it possible or not?

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

0

This will return the first day of the given week:

var dateString = "2020-44";
function getDateFromWeek(str) {
    var y = str.split('-')[0]
    var w = str.split('-')[1]
    var d = (1 + (w - 1) * 7); // 1st of January + 7 days for each week

    return new Date(y, 0, d);
}
console.log(getDateFromWeek(dateString));

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!