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)
📘 Initial Data Setup — students3 (dob as ISODate)
1️⃣ $hour — Extract Hour (0–23)
2️⃣ $minute — Extract Minute (0–59)
3️⃣ $second — Extract Second (0–59)
4️⃣ $millisecond — Extract Milliseconds (0–999)
5️⃣ $dayOfMonth — Day of Month (1–31)
6️⃣ $dayOfWeek — Day of Week (1=Sunday…7=Saturday)
7️⃣ $dayOfYear — Day of Year (1–366)
8️⃣ $week — Week of Year (1–53)
9️⃣ $isoWeek — ISO Week (1–53)
🔟 $isoWeekYear — ISO Week-Year
1️⃣1️⃣ $isoDayOfWeek — ISO Day of Week (1=Mon…7=Sun)
1️⃣2️⃣ $month — Month (1–12)
1️⃣3️⃣ $year — Year (e.g., 2010)
1️⃣4️⃣ $dateFromString — Parse String to Date
1️⃣5️⃣ $dateToString — Format Date as String
1️⃣6️⃣ $dateFromParts — Build a Date from Components
1️⃣7️⃣ $dateToParts — Decompose a Date
1️⃣8️⃣ $toDate — Convert Value to Date
1️⃣9️⃣ $dateAdd — Add Time to a Date
2️⃣0️⃣ $dateSubtract — Subtract Time from a Date
2️⃣1️⃣ $dateDiff — Difference Between Dates
2️⃣2️⃣ $dateTrunc — Truncate Date to Unit
Keep Going!MongoDB - Array Operators