Search code examples
angulartypescriptdate-pipe

week number of the year by a given date


I got the date as follow

const today = new Date();

now I need to get the week number of the year. How do I get it on the typescript?

I tried const todayFormated = this.datepipe.transform(today, 'W'); but it is returning the week number of the month not year


Solution

  • It is lowercase 'w': const todayFormated = this.datepipe.transform(today, 'w');.

    From the Angular Documentation:

    Week of year w Numeric: minimum digits 1... 53

    Week of month W Numeric: 1 digit 1... 5