> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# $isoWeek (expression operator)

## Definition

Returns the week number in ISO 8601 format, ranging from `1` to `53`. Week numbers start at `1` with the week (Monday through Sunday) that contains the year's first Thursday.

The [`$isoWeek`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoweek.md#mongodb-expression-exp.-isoWeek) expression has the following [operator expression syntax:](https://www.mongodb.com/docs/manual/reference/mql/expressions.md#std-label-aggregation-expressions)

```javascript
{ $isoWeek: <dateExpression> }
```

The argument can be:

- An [expression](https://www.mongodb.com/docs/manual/reference/mql/expressions.md#std-label-aggregation-expressions) that resolves to a [Date](https://www.mongodb.com/docs/manual/reference/bson-types.md#std-label-document-bson-type-date), a [Timestamp](https://www.mongodb.com/docs/manual/reference/bson-types.md#std-label-document-bson-type-timestamp), or an [ObjectID.](https://www.mongodb.com/docs/manual/reference/bson-types.md#std-label-document-bson-type-object-id)

- A document with this format:

  ```javascript
  { date: <dateExpression>, timezone: <tzExpression> }
  ```

  | Field | Description |
  | --- | --- |
  | `date` | The date to which the operator is applied. `<dateExpression>` must be a valid [expression](https://www.mongodb.com/docs/manual/reference/mql/expressions.md#std-label-aggregation-expressions) that resolves to a [Date](https://www.mongodb.com/docs/manual/reference/bson-types.md#std-label-document-bson-type-date), a [Timestamp](https://www.mongodb.com/docs/manual/reference/bson-types.md#std-label-document-bson-type-timestamp), or an [ObjectID.](https://www.mongodb.com/docs/manual/reference/bson-types.md#std-label-document-bson-type-object-id) |
  | `timezone` | Optional. The timezone of the operation result. `<tzExpression>` must be a valid [expression](https://www.mongodb.com/docs/manual/reference/mql/expressions.md#std-label-aggregation-expressions) that resolves to a string formatted as either an [Olson Timezone Identifier](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) or a [UTC Offset](https://en.wikipedia.org/wiki/List_of_UTC_time_offsets). If no `timezone` is provided, the result is in UTC. `Olson Timezone Identifier`:`"America/New_York"
  "Europe/London"
  "GMT"`; `UTC Offset`:`+/-[hh]:[mm], e.g. "+04:45"
  +/-[hh][mm], e.g. "-0530"
  +/-[hh], e.g. "+03"` |

## Behavior

| Example | Result |
| --- | --- |
| `{ $isoWeek: { date: new Date("Jan 4, 2016") } }` | 1 |
| `{ $isoWeek: new Date("2016-01-01") }` | 53 |
| `{ $isoWeek: {
    date: new Date("August 14, 2011"),
    timezone: "America/Chicago"
} }` | 32 |
| `{ $isoWeek: ISODate("1998-11-02T00:00:00Z") }` | 45 |
| `{ $isoWeek: {
    date: ISODate("1998-11-02T00:00:00Z"),
    timezone: "-0500"
} }` | 44 |
| `{ $isoWeek: "March 28, 1976" }` | `error` |
| `{ $isoWeek: Date("2016-01-01") }` | `error` |
| `{ $isoWeek: "2009-04-09" }` | `error` |

**Note: $isoWeek cannot take a string as an argument.**

## Example

A collection called `deliveries` contains the following documents:

```javascript
db.deliveries.insertMany( [
   { _id: 1, date: ISODate("2006-10-24T00:00:00Z"), city: "Boston" },
   { _id: 2, date: ISODate("2011-08-18T00:00:00Z"), city: "Detroit" }
] )
```

The following operation returns the week number for each `date` field.

```javascript
db.deliveries.aggregate( [
  {
    $project: {
      _id: 0,
      city: "$city",
      weekNumber: { $isoWeek: "$date" }
    }
  }
] )
```

The operation returns the following results:

```javascript
[
   { city: "Boston", weekNumber: 43 },
   { city: "Detroit", weekNumber: 33 }
]
```

**See also:**

- [$isoDayOfWeek (expression operator)](https://www.mongodb.com/docs/manual/reference/operator/aggregation/isodayofweek.md)

- [$isoWeekYear (expression operator)](https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoweekyear.md)
