endofyear function in APL to return the end of the year containing a given datetime value. The function returns a datetime representing the last moment of that year (December 31, 23:59:59.9999999).
You can use endofyear to align events to year-end boundaries, which is useful for annual aggregation, fiscal year analysis, and year-over-year comparisons in dashboards.
Use it when you want to:
- Group events by year-end boundaries for annual reporting.
- Compare activity or metrics across calendar years.
- Align timestamps to the end of the year for time-series bucketing.
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
endofyear. You typically need to extract the year and manually construct the year-end timestamp. In APL, the endofyear function returns the last moment of the year in a single call.ANSI SQL users
ANSI SQL users
In ANSI SQL, you can calculate the end of the year by truncating to the year and adding an interval. Different SQL platforms offer varying syntax for this. In APL,
endofyear provides this in a single function call.Usage
Syntax
Parameters
| Name | Type | Description |
|---|---|---|
| datetime | datetime | The input datetime value. |
| offset | long | Optional: The number of years to offset from the input datetime. Default is 0. |
Returns
Adatetime representing the end of the year for the given date, shifted by the offset if specified. The return value is December 31 at 23:59:59.9999999 of the input year.
Use case examples
- Log analysis
- OpenTelemetry traces
- Security logs
Count total HTTP requests per year to understand annual traffic volume.QueryRun in PlaygroundOutput
This query groups each HTTP log entry by its year-end boundary and counts the total number of requests per year.
| year_end | total_requests |
|---|---|
| 2024-12-31T23:59:59.9999999Z | 1523 |
| 2025-12-31T23:59:59.9999999Z | 2841 |
List of related functions
- startofyear: Returns the start of the year for a datetime value.
- endofmonth: Returns the end of the month for a datetime, useful for monthly boundary calculations.
- endofweek: Returns the end of the week for a datetime value.
- endofday: Returns the end of the day for a datetime value.
- getyear: Extracts the year part from a datetime as an integer.