dayOfMonth() : Extract Day from Date
On this page
Summary
Extract the day of the month component from a datetime value as a number (1-31).
Signature
dayOfMonth(date)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
date |
DateTime | Yes | The datetime to extract the day from |
Returns
Type: Number (Integer)
The day of the month as a number from 1 to 31.
Examples
Display Day
Data:
doc.Params["model"] = new {
date = new DateTime(2024, 3, 15)
};
Output:
<p>Day: 15</p>
Custom Date Format
Data:
doc.Params["model"] = new {
date = new DateTime(2024, 3, 5)
};
Output:
<p>Date: 2024-03-05</p>
Day Range Filter
Data:
doc.Params["model"] = new {
events = new[] {
new { date = new DateTime(2024, 3, 10), title = "Team Meeting" },
new { date = new DateTime(2024, 3, 20), title = "Project Review" },
new { date = new DateTime(2024, 3, 5), title = "Sprint Planning" }
}
};
Output:
<h3>Events in First Half of Month</h3>
<p>Mar 10: Team Meeting</p>
<p>Mar 05: Sprint Planning</p>
Payment Schedule
Data:
doc.Params["model"] = new {
today = new DateTime(2024, 3, 10)
};
Output:
<p>Next payment due: March 15</p>
Notes
- Returns numeric value 1-31
- Actual maximum depends on the month (28-31)
- Time component is ignored
- Useful for custom date formatting and date-based logic
- For day of week, use
dayOfWeek()function - For day of year, use
dayOfYear()function