- Reference >
- Operators >
- Aggregation Pipeline Operators >
- Date Aggregation Operators >
- $isoWeek (aggregation)
$isoWeek (aggregation)¶
On this page
Definition¶
-
$isoWeek
¶ New in version 3.4.
Returns the week number in ISO 8601 format, ranging from
1
to53
. Week numbers start at1
with the week (Monday through Sunday) that contains the year’s first Thursday.$isoWeek has the following operator expression syntax:
The argument can be any valid expression that resolves to a BSON ISODate object, a BSON Timestamp object, or a Date object.
Behavior¶
Example | Result |
---|---|
{ $isoWeek: new Date("2016-01-01") } |
53 |
{ $isoWeek: new Date("2015-01-01") } |
1 |
{ $isoWeek: new Date("August 14, 2011") } |
32 |
{ $isoWeek: ISODate("1998-11-07T00:00:00Z") } |
45 |
{ $isoWeek: "March 28, 1976" } |
error |
{ $isoWeek: "2009-04-09" } |
error |
Note
$isoWeek
cannot take a string as an argument.
Example¶
A collection called deliveries
contains the following documents:
The following operation returns the week number for each date
field.
The operation returns the following results: