Skip to main content

$weekOfYear

The $weekOfYear operator extracts the week of the year from a date object (0-53).

Input

  • A single date object

Output

  • The week of the year as an integer (0-53, where 0 is the first week)

Examples

Extract Week of Year from Date

{
  "$weekOfYear": [
    {
      "$toDate": ["2023-01-15T10:30:00Z"]
    }
  ]
}
Result: 1 (Week number 2, 0-indexed as 1)

Extract Week of Year from Field

{
  "$weekOfYear": [
    {
      "$input": "event_date"
    }
  ]
}
Result: The week of the year (0-53) of the event_date field