endofweek function in APL to calculate the end of the week for a given datetime value. The function returns a datetime set to the last moment of Saturday (23:59:59.9999999), with an optional offset to shift forward or backward by a specified number of weeks.
You can use endofweek to create weekly time boundaries for aggregation, reporting, and trend analysis. This is especially useful when you need to bucket events into weekly intervals or define weekly reporting windows.
Use it when you want to:
- Define end-of-week boundaries for weekly reports and dashboards.
- Aggregate events to weekly intervals for trend analysis.
- Build weekly 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
endofweek. You typically use manual date arithmetic with eval and relative_time to calculate the end of the week. In APL, the endofweek function handles this directly and supports an optional week offset.ANSI SQL users
ANSI SQL users
In ANSI SQL, you typically combine
DATE_TRUNC with interval arithmetic to calculate the end of the week. The exact behavior depends on how each platform defines the start of the week. In APL, endofweek returns the end of the week as Saturday 23:59:59.9999999.Usage
Syntax
Parameters
| Name | Type | Description |
|---|---|---|
| datetime | datetime | The input datetime value. |
| offset | long | Optional: The number of weeks to offset from the input date. Default is 0. |
Returns
Adatetime representing the end of the week (Saturday 23:59:59.9999999) for the given date, shifted by the offset if specified.
Use case examples
- Log analysis
- OpenTelemetry traces
- Security logs
Summarize total requests per week to track weekly traffic volume.QueryRun in PlaygroundOutput
This query groups HTTP log events by end-of-week boundaries and counts the total requests in each week.
| week_end | total_requests |
|---|---|
| 2024-11-16T23:59:59.9999999Z | 4521 |
| 2024-11-23T23:59:59.9999999Z | 4837 |
| 2024-11-30T23:59:59.9999999Z | 4392 |
List of related functions
- startofweek: Returns the start of the week for a datetime, useful for defining the beginning of weekly intervals.
- endofday: Returns the end of the day for a datetime.
- endofmonth: Returns the end of the month for a datetime.
- endofyear: Returns the end of the year for a datetime.
- week_of_year: Returns the ISO 8601 week number, useful for week-based grouping.