Skip to main content

$year

The $year operator extracts the year component from a date object.

Input

  • A single date object

Output

  • The year component of the date as an integer

Examples

Extract Year from Date

{
  "$year": [
    {
      "$toDate": ["2023-01-15T10:30:00Z"]
    }
  ]
}
Result: 2023

Extract Year from Field

{
  "$year": [
    {
      "$input": "birth_date"
    }
  ]
}
Result: The year component of the birth_date field