Search code examples
javascriptangularjsmomentjsangular-moment

Get days of the week based on week number


Is there a way to get the Sunday thru Saturday dates of the week based on week number?

For example the current week number is 32, so I would want an array (or some return type) as such:

["Sunday, July 3rd, 2016", "Monday, July 4th, 2016".... etc  ] 

The documentation here states that use can use the syntax below, however this seems to simply gives me the current day (unless I'm reading the output wrong).

moment().weeks(32)

Output: Fri Aug 05 2016 11:19:39 GMT-0400


Solution

  • Would suggest to not go for additional libraries. Once you get first day for given week number using moment().weeks(32), write a simple method to return next seven days using moment().add() method.