Sorry found solution myself:
var test = moment().day("Monday").week(week number here);
Question
As mentioned in the title, I have a week number and a year value. Is there a way of finding Monday of that week using moment.js? Was trying, but not succeeded
Solution
Sorry found solution myself:
var test = moment().day("Monday").week(week number here);
OTHER TIPS
Building off the answers provided here...
exports.getDateFromWeek = function(week, year) {
return moment().day("Monday").year(year).week(week).toDate();
};
Personally, I wanted the first Sunday... and in which case it's:
exports.getDateFromWeek = function(week, year) {
return moment().day("Sunday").year(year).week(week).toDate();
};
Try like this:-
var weekdate= function(year, week, dayNumber)
{
var j1 = new Date( year,0,10,12,0,0),
j2 = new Date( year,0,4,12,0,0),
mon1 = j2.getTime() - j1.getDay() * 86400000;
return new Date(mon1 + ((week- 1) * 7 + dayNumber) * 86400000);
};
console.log(weekdate(2010, 1, 4));
2010
starts with Thursady
moment('2021').add(16, 'weeks').startOf('week').format('DD MM YYYY');
Starts on Sunday. The above code result is "18 04 2021"
moment('2021').add(16, 'weeks').startOf('isoweek').format('DD MM YYYY');
Starts on Monday. The above code result is "19 04 2021"