- Reference >
- Operators >
- Aggregation Pipeline Operators >
- Date Aggregation Operators >
- $isoWeekYear (aggregation)
$isoWeekYear (aggregation)¶
On this page
Definition¶
-
$isoWeekYear
¶ New in version 3.4.
Returns the year number in ISO 8601 format. The year starts with the Monday of week 1 (ISO 8601) and ends with the Sunday of the last week (ISO 8601).
$isoWeekYear 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 |
---|---|
{ $isoWeekYear: new Date("2016-01-01") } |
2015 |
{ $isoWeekYear: new Date("2015-01-01") } |
2015 |
{ $isoWeekYear: new Date("2016-01-04") } |
2016 |
{ $isoWeekYear: "2016-01-01" } |
error |
Note
$isoWeekYear
cannot take a string as an argument.
Example¶
A collection called anniversaries
contains the following documents:
The following operation returns the year number in ISO 8601
format for each date
field.
The operation returns the following results: