Skip to main content

$dayOfYear

The $dayOfYear operator extracts the day of the year from a date object (0-365).

Input

  • A single date object

Output

  • The day of the year as an integer (0-365, where 0 is January 1)

Examples

Extract Day of Year from Date

{
  "$dayOfYear": [
    {
      "$toDate": ["2023-01-15T10:30:00Z"]
    }
  ]
}
Result: 14 (January 15 is the 15th day of the year, 0-indexed as 14)

Extract Day of Year from Field

{
  "$dayOfYear": [
    {
      "$input": "event_date"
    }
  ]
}
Result: The day of the year (0-365) of the event_date field