Skip to content

Latest commit

 

History

History
36 lines (26 loc) · 968 Bytes

weekOfYear.md

File metadata and controls

36 lines (26 loc) · 968 Bytes

Back to reference

weekOfYear(date, returnYear = false)

Returns the week number according to ISO-8601 of the given date's year.

Note: The first week of the year is the week with January 4th in it. Weeks start on Monday.

Example1:

If you have a date like this:

const date = new Date("2021-05-17");

This will calculate and give back the week number:

let week = gmynd.weekOfYear(date);

// returns: 20

Example 2:

Let's take this precious date:

const date = new Date("2021-01-01");

When you also need the year of the given week number, you can pass true for the returnYear parameter:

let week = gmynd.weekOfYear(date, true);

// returns: Array [ 2020, 53 ]

Note that this date still belongs to the last week of the previous year.

credits to RobG