Nearby lessons
17 of 22🗓️ MongoDB: Date Aggregation Operators
MongoDB provides powerful Date Aggregation Operators that allow you to manipulate and extract components
such as year, month, day, hour, and more from date fields. These operators are essential when performing
time-based analytics, formatting dates, and creating reports.
📚 Initial Data Setup — students (dob as string)
Example01
Loading editor…
📘 Initial Data Setup — students3 (dob as ISODate)
Example02
Loading editor…
1️⃣ $hour — Extract Hour (0–23)
Example03
Loading editor…
2️⃣ $minute — Extract Minute (0–59)
Example04
Loading editor…
3️⃣ $second — Extract Second (0–59)
Example05
Loading editor…
4️⃣ $millisecond — Extract Milliseconds (0–999)
Example06
Loading editor…
5️⃣ $dayOfMonth — Day of Month (1–31)
Example07
Loading editor…
6️⃣ $dayOfWeek — Day of Week (1=Sunday…7=Saturday)
Example08
Loading editor…
7️⃣ $dayOfYear — Day of Year (1–366)
Example09
Loading editor…
8️⃣ $week — Week of Year (1–53)
Example10
Loading editor…
9️⃣ $isoWeek — ISO Week (1–53)
Example11
Loading editor…
🔟 $isoWeekYear — ISO Week-Year
Example12
Loading editor…
1️⃣1️⃣ $isoDayOfWeek — ISO Day of Week (1=Mon…7=Sun)
Example13
Loading editor…
1️⃣2️⃣ $month — Month (1–12)
Example14
Loading editor…
1️⃣3️⃣ $year — Year (e.g., 2010)
Example15
Loading editor…
1️⃣4️⃣ $dateFromString — Parse String to Date
Example16
Loading editor…
1️⃣5️⃣ $dateToString — Format Date as String
Example17
Loading editor…
1️⃣6️⃣ $dateFromParts — Build a Date from Components
Example18
Loading editor…
1️⃣7️⃣ $dateToParts — Decompose a Date
Example19
Loading editor…
1️⃣8️⃣ $toDate — Convert Value to Date
Example20
Loading editor…
1️⃣9️⃣ $dateAdd — Add Time to a Date
Example21
Loading editor…
2️⃣0️⃣ $dateSubtract — Subtract Time from a Date
Example22
Loading editor…
2️⃣1️⃣ $dateDiff — Difference Between Dates
Example23
Loading editor…
2️⃣2️⃣ $dateTrunc — Truncate Date to Unit
Example24
Loading editor…
Finished this lesson?
Mark it as complete to track your progress and see technology completion stats.