hourofday function in APL to extract the hour of the day from a datetime value. The function returns an integer from 0 to 23, where 0 represents midnight and 23 represents 11 PM.
You can use hourofday to group records by hour for time-of-day analysis, peak traffic identification, and intraday pattern detection. This is useful for operational dashboards, capacity planning, and anomaly detection.
Use it when you want to:
- Identify peak traffic hours in your services.
- Analyze hourly patterns in request volume or error rates.
- Create time-of-day summaries across log, trace, or security datasets.
For users of other query languages
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.Splunk SPL users
Splunk SPL users
In Splunk SPL, you typically use the
strftime function with the %H specifier to extract the hour of the day. In APL, the hourofday function directly returns the hour as an integer.ANSI SQL users
ANSI SQL users
In ANSI SQL, you use
EXTRACT(HOUR FROM timestamp) or the HOUR() function to get the hour. In APL, hourofday provides the same result.Usage
Syntax
Parameters
| Name | Type | Description |
|---|---|---|
| datetime | datetime | The input datetime value. |
Returns
Anint from 0 to 23 representing the hour of the day.
Use case examples
- Log analysis
- OpenTelemetry traces
- Security logs
Analyze HTTP request volume by hour to identify peak traffic periods.QueryRun in PlaygroundOutput
This query groups HTTP log entries by hour and counts the requests per hour, revealing peak and off-peak periods.
| hour | request_count |
|---|---|
| 0 | 312 |
| 1 | 287 |
| 14 | 1523 |
List of related functions
- dayofweek: Returns the day of the week as a timespan, complementing hourly analysis with day-level detail.
- dayofmonth: Returns the day of the month from a datetime.
- datetime-part: Extracts a specific date part (such as hour) as an integer.
- startofday: Returns the start of the day for a datetime, useful for daily binning.
- endofday: Returns the end of the day for a datetime value.