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
Asked
Active
Viewed 4.5k times
4 Answers
107
Sorry found solution myself:
var test = moment().day("Monday").week(week number here);

Bartosz
- 4,542
- 11
- 43
- 69
-
2How to get the date from a week number for a particular year? Thanks – codingbbq Feb 19 '15 at 12:19
-
9You would probably use moment().year(2014).week(weeknum); – mix3d Apr 22 '15 at 18:51
-
3To get the beginning of the week use: moment().year(2018).week(25).day('monday').format('MMMM Do YYYY'); – Scott Wright Jun 20 '18 at 17:26
20
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();
};

blak3r
- 16,066
- 16
- 78
- 98
2
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

Rahul Tripathi
- 168,305
- 31
- 280
- 331
-
7The OP asked for a solution using Moment.js. As far as I can tell, this does not answer the question. – cdeszaq Mar 04 '14 at 15:50
1
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"

Sam
- 149
- 4
- 15