monthofyear function in APL to extract the month number from a datetime value. The function returns an integer from 1 to 12, where 1 represents January and 12 represents December.
The monthofyear and getmonth functions return the same result. Use either interchangeably.
You can use monthofyear to group records by month when analyzing seasonal patterns, month-over-month comparisons, or periodic trends. This is useful for dashboards, monthly reporting, and cohort analysis.
Use it when you want to:
- Aggregate events by month for seasonal trend analysis.
- Compare metrics month over month to detect recurring patterns.
- Create monthly 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 %m specifier to extract the month number. In APL, the monthofyear function directly returns the month number as an integer.ANSI SQL users
ANSI SQL users
In ANSI SQL, you use
EXTRACT(MONTH FROM timestamp) or the MONTH() function to get the month number. In APL, monthofyear provides the same result.Usage
Syntax
Parameters
| Name | Type | Description |
|---|---|---|
| datetime | datetime | The input datetime value. |
Returns
Anint from 1 to 12 representing the month number of the year.
Use case examples
- Log analysis
- OpenTelemetry traces
- Security logs
Analyze average request duration by month to identify seasonal performance variations.QueryRun in PlaygroundOutput
This query calculates the average request duration per month, helping you spot months with degraded performance.
| month | avg_duration |
|---|---|
| 1 | 243.8 |
| 2 | 238.5 |
| 3 | 251.2 |
List of related functions
- getmonth: Returns the month number from a datetime. Equivalent to
monthofyear. - getyear: Extracts the year part from a datetime as an integer.
- dayofmonth: Returns the day of the month from a datetime.
- startofmonth: Returns the start of the month for a datetime, useful for monthly binning.
- endofmonth: Returns the end of the month for a datetime value.