$dayOfMonth (Get Day of Month)

Last updated: 2026-10-09

$dayOfMonth (Get Day of Month)

$dayOfMonth returns the day of month of a date (1 to 31) — a common expression for day-level stats. It accepts either a plain date expression or an object with an explicit timezone. Typical uses: grouping orders by day, building day labels, or detecting month starts. It returns an integer; the day may differ across zones, so always set timezone (defaults to UTC).

CategoryDate
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

{ $dayOfMonth: { date: <date-expression>, timezone: <timezone> } }

⚙️ Parameters

dateRequired; the date expression.
timezoneOptional timezone; defaults to UTC.

Returns:The day of month (1-31) as an integer; null if date is null.

▶ Example

Run the commands below in your local mongosh (requires a running mongod):

// $dayOfMonth: get order day (Beijing time)
 db.orders.aggregate([
  { $project: {
      day: { $dayOfMonth: { date: '$orderDate', timezone: 'Asia/Shanghai' } }
  } }
])

Output:

{ "_id": 1, "day": 25 }
{ "_id": 2, "day": 1 }

📌 Notes

More hands-on cases coming soon.

📚 Related Tutorials

❓ FAQ

QWhat differs between $dayOfMonth and %d?
A%d outputs a two-digit string (05); $dayOfMonth outputs an integer (5).
QDoes it start at 0 or 1?
AStarts at 1 — the 1st of a month is 1.
QDoes timezone affect the result?
AYes — UTC and local zones can give different days; set timezone explicitly.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏