endofmonth function in APL to calculate the end of the month for a given datetime value. The function returns a datetime set to the last moment of the final day of the month (23:59:59.9999999), with an optional offset to shift forward or backward by a specified number of months.
You can use endofmonth to create monthly time boundaries for aggregation, billing cycles, and reporting. This is especially useful when you need to bucket events into monthly intervals or define month-end deadlines.
Use it when you want to:
- Define end-of-month boundaries for monthly reports and dashboards.
- Aggregate events to monthly intervals for billing or usage analysis.
- Build 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, there is no direct equivalent to
endofmonth. You typically use manual date math with eval and relative_time to calculate the last day of the month. In APL, the endofmonth function handles this directly and supports an optional month offset.ANSI SQL users
ANSI SQL users
In ANSI SQL, you often use
LAST_DAY(timestamp) or combine DATE_TRUNC with interval arithmetic to get the end of the month. In APL, the endofmonth function provides this directly and supports an optional month offset.Usage
Syntax
Parameters
| Name | Type | Description |
|---|---|---|
| datetime | datetime | The input datetime value. |
| offset | long | Optional: The number of months to offset from the input date. Default is 0. |
Returns
Adatetime representing the last moment of the month for the given date, shifted by the offset if specified.
Use case examples
- Log analysis
- OpenTelemetry traces
- Security logs
Count requests by month boundary to track monthly traffic volume.QueryRun in PlaygroundOutput
This query groups HTTP log events by end-of-month boundaries and counts the total requests in each month.
| month_end | total_requests |
|---|---|
| 2024-10-31T23:59:59.9999999Z | 18432 |
| 2024-11-30T23:59:59.9999999Z | 19871 |
| 2024-12-31T23:59:59.9999999Z | 17654 |
List of related functions
- startofmonth: Returns the start of the month for a datetime, useful for defining the beginning of monthly intervals.
- endofday: Returns the end of the day for a datetime.
- endofweek: Returns the end of the week for a datetime.
- endofyear: Returns the end of the year for a datetime.
- monthofyear: Returns the month number from a datetime, useful for month-based grouping.