# ISO\_WEEK

**The function ISO\_WEEK takes a Date or a DateTime and returns a Number indicating the ISO week of the year that the given date falls on.**

This function takes either a single [DateTime](../../variable-data-types/the-datetime-variable-data-type) or a single [Date](../../variable-data-types/the-date-variable-data-type) as input. It then a returns a [Number](../../variable-data-types/the-number-variable-data-type) indicating what [ISO week](https://en.wikipedia.org/wiki/ISO_week_date) of the year the given date falls on. Weeks start with Monday, and each week's year is the Gregorian year in which the Thursday falls.&#x20;

#### Declaration

```javascript
ISO_WEEK(datetime) -> iso_week_number
```

```javascript
ISO_WEEK(date) -> iso_week_number
```

&#x20;

#### Parameters

**datetime** (type: _DateTime_) Any DateTime.

**date** (type: _DateTime_) Any Date.

#### Return Values

**iso\_week\_number** (type: _Number_) A number indicating what ISO week of the year is described by the given Date or DateTime. Count starts with 1. Weeks start with Monday, and each week's year is the Gregorian year in which the Thursday falls. That is, if the first day of the year falls on a Friday, Saturday, or a Sunday, it will count as being in the last week of the previous year, rather than the first week of the current year.

#### Examples

Assume the first example has access to the following DateTime value:

```javascript
example_date_and_time = {  
 "date": {  
  "day": 1,  
  "month": 1,  
  "year": 2021  
 },  
 "time": {  
  "hour": 16,  
  "minute": 14,  
  "second": 38,  
  "millisecond": 0  
 },  
 "timeZone": "UTC"  
}
```

The date described in **example\_date\_and\_time** is January 1st, 2021, the first day of the year. In 2021, the first day of the year falls on a Friday; as Friday comes after Thursday, January 1st, 2021 counts as part of the last week of 2020 instead of as part of the first week of 2021. This is reflected in the following example, where **example\_date\_and\_time** is provided as input for the function ISO\_WEEK:

```javascript
ISO_WEEK(example_date_and_time) = 53
```

The above example demonstrates how the ISO\_WEEK function behaves when given a DateTime as input. In order to further establish how the ISO\_WEEK function behaves when given a Date rather than a DateTime, assume the next example has access to the following date value:

```javascript
example_date = {  
 "day": 1,  
 "month": 1,  
 "year": 2021  
}
```

Note that the date described in **example\_date** is identical to the date described in **example\_date\_and\_time**. This is still the first day of 2021, and when **example\_date** is given as input for ISO\_WEEK, it again returns the number 53:

```javascript
ISO_WEEK(example_date) = 53
```

January 1, 2021 falls on a Friday. This means that week 1 (as defined by the ISO\_WEEK function) starts not on January 1, 2021, but on January 4, 2021, the first Monday in 2021 (in the week that contains the first Thursday of 2021). This is the date given by the following date, **example\_date2**:

```javascript
example_date2 = {  
 "day": 4,  
 "month": 1,  
 "year": 2021  
}
```

The following example outputs the ISO week of the year associated with January 4, 2021, The first ISO week of 2021:

```javascript
ISO_WEEK(example_date2) = 1
```

While Monday, January 4, 2021 counts as part of the first week of 2021, the day before it, a Sunday, doesn't. To demonstrate this, assume the last example has access to the following date:

```javascript
example_date3 = {  
 "day": 3,  
 "month": 1,  
 "year": 2021  
}
```

**example\_date3** describes Monday January 3, 2021, which is what the ISO\_WEEK function considers the last day of the last week of 2020. Thus, when **example\_date3** is given as input for the WEEK function, it returns the number 53, as in the following example:

```javascript
ISO_WEEK(example_date3) = 53
```

#### Discussion

As far as the ISO\_WEEK function is concerned, weeks start with Monday, and each week's year is the Gregorian year in which the Thursday falls. That is, if the first day of the year falls on a Friday, Saturday, or a Sunday, it will count as being in the last week of the previous year, rather than the first week of the current year. The examples discussed above demonstrated this by examining the first week in January 2021, for which the following calendar can serve as an individual aid:

![Screen\_Shot\_2021-04-16\_at\_10.22.35\_AM.png](https://2599974655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIRF6etABDVMr59RdpyGw%2Fuploads%2Fgit-blob-4248282564581850b52536977e234ca25606286a%2Fiso_week-v184-0.png?alt=media)
