$dayOfYear
The $dayOfYear operator in Amazon DocumentDB returns the day of the year for a date as a number between 1 and 366 (365 in non-leap years).
Parameters
-
expression: The date field or expression from which to extract the day of the year.
Example (MongoDB Shell)
This example demonstrates how to use the $dayOfYear operator to extract the day of the year from a date field in an Amazon DocumentDB collection.
Create sample documents
db.weather.insert([ { "temperature" : 97.5, "humidity": 0.60, "date" : new Date("2023-03-15") }, { "temperature" : 82.3, "humidity": 0.75, "date" : new Date("2023-12-31") } ])
Query example
db.weather.aggregate([ { $project: { dayOfYear: { $dayOfYear: "$date" } } } ]).pretty()
Output
{ "_id" : ObjectId("642b86fc7d8e07af279bbe63"), "dayOfYear" : 74 }
{ "_id" : ObjectId("642b86fc7d8e07af279bbe64"), "dayOfYear" : 365 }
Code examples
To view a code example for using the $dayOfYear command, choose the tab for the language that you want to use: