hourOf() : Extract Hour from DateTime
On this page
Summary
Extract the hour component from a datetime value as a 24-hour format number (0-23).
Signature
hourOf(datetime)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
datetime |
DateTime | Yes | The datetime to extract the hour from |
Returns
Type: Number (Integer)
The hour in 24-hour format as a number from 0 (midnight) to 23 (11 PM).
Examples
Display Hour
Data:
doc.Params["model"] = new {
time = new DateTime(2024, 3, 15, 14, 30, 0)
};
Output:
<p>Hour: 14</p>
Business Hours Check
Data:
doc.Params["model"] = new {
currentTime = new DateTime(2024, 3, 15, 10, 30, 0)
};
Output:
<p>Status: Open</p>
Shift Assignment
Data:
doc.Params["model"] = new {
clockIn = new DateTime(2024, 3, 15, 14, 0, 0)
};
Output:
<p>Shift: Day Shift (8 AM - 4 PM)</p>
Peak Hour Pricing
Data:
doc.Params["model"] = new {
transactions = new[] {
new { time = new DateTime(2024, 3, 15, 14, 30, 0), amount = 5.00 },
new { time = new DateTime(2024, 3, 15, 18, 15, 0), amount = 7.50 },
new { time = new DateTime(2024, 3, 15, 21, 0, 0), amount = 5.00 }
}
};
Output:
<p>2:30 PM: $5</p>
<p>6:15 PM: $7.5 (Peak Rate)</p>
<p>9:00 PM: $5</p>
Notes
- Returns 0-23 in 24-hour format
- 0 = midnight, 12 = noon, 23 = 11 PM
- Date component is ignored
- For 12-hour format display, use
format(datetime, 'h tt')orformat(datetime, 'hh tt') - Useful for:
- Business hours logic
- Shift scheduling
- Time-of-day pricing
- Activity categorization by hour
- For full time formatting, use
format()function