Rakesh Prasad
Rakesh Prasad

Reputation: 642

I'm trying to generate date from week number using moment JS

As per the documentation, the following code should work:

moment(moment('2020043').format("YYYYwwe")).format("YYYY-MM-DD");

I'm trying to get 3rd day of 4th week of 2020

jsfiddle code

Upvotes: 0

Views: 59

Answers (1)

VincenzoC
VincenzoC

Reputation: 31482

No, you have to use moment(String, String) and use YYYYWWE as parsing tokens (case sensitive), where YYYY is the 4 digit year WW is ISO week of year and E is ISO day of week.

Example:

console.log(moment('2020043', "YYYYWWE").format("YYYY-MM-DD"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>

Upvotes: 1

Related Questions