endofweek
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.
Usage#
Syntax#
endofweek(datetime [, offset])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#
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 ascOutput
| 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 |
This query groups HTTP log events by end-of-week boundaries and counts the total requests in each week.
Track weekly average span duration for each service to monitor performance trends over time.
Query
['otel-demo-traces']
| extend week_end = endofweek(_time)
| summarize avg_duration = avg(duration) by week_end, ['service.name']
| sort by week_end ascOutput
| week_end | service.name | avg_duration |
|---|---|---|
| 2024-11-16T23:59:59.9999999Z | frontend | 00:00:01.2430000 |
| 2024-11-23T23:59:59.9999999Z | frontend | 00:00:01.1870000 |
| 2024-11-30T23:59:59.9999999Z | frontend | 00:00:01.3010000 |
This query shows how average span duration changes week by week for each service, helping you spot performance regressions.
Monitor weekly error trends to detect sustained increases in server failures.
Query
['sample-http-logs']
| where toint(status) >= 500
| extend week_end = endofweek(_time)
| summarize error_count = count() by week_end
| sort by week_end ascOutput
| week_end | error_count |
|---|---|
| 2024-11-16T23:59:59.9999999Z | 52 |
| 2024-11-23T23:59:59.9999999Z | 78 |
| 2024-11-30T23:59:59.9999999Z | 41 |
This query counts server errors by week to help you identify weeks with elevated failure rates.
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.
Other query languages#
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.
Splunk example
... | eval week_end=relative_time(now(), "@w7+6d@d+86399")APL equivalent
... | extend week_end = endofweek(_time)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.
SQL example
SELECT DATE_TRUNC('week', timestamp_column) + INTERVAL '7 days' - INTERVAL '1 second' AS week_end FROM events;APL equivalent
['dataset']
| extend week_end = endofweek(_time)