Skip to main content
Use the 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.
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.
... | eval week_end=relative_time(now(), "@w7+6d@d+86399")
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.
SELECT DATE_TRUNC('week', timestamp_column) + INTERVAL '7 days' - INTERVAL '1 second' AS week_end FROM events;

Usage

Syntax

endofweek(datetime [, offset])

Parameters

NameTypeDescription
datetimedatetimeThe input datetime value.
offsetlongOptional: The number of weeks to offset from the input date. Default is 0.

Returns

A datetime representing the end of the week (Saturday 23:59:59.9999999) for the given date, shifted by the offset if specified.

Use case examples

Summarize total requests per week to track weekly traffic volume.Query
['sample-http-logs']
| extend week_end = endofweek(_time)
| summarize total_requests = count() by week_end
| sort by week_end asc
Run in PlaygroundOutput
week_endtotal_requests
2024-11-16T23:59:59.9999999Z4521
2024-11-23T23:59:59.9999999Z4837
2024-11-30T23:59:59.9999999Z4392
This query groups HTTP log events by end-of-week boundaries and counts the total requests in each week.
  • 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.