endofweek()
Learn how to use the endofweek() function to return a datetime representing the end of the week for the given date value.
Provides the end of the week containing the date, shifted by an offset, if provided.
Last day of the week is considered to be a Saturday.
Syntax
endofweek(date [, offset])
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| date | datetime | ✔️ | The date used to find the end of the week. |
| offset | int | The number of offset weeks from date. Default is 0. |
Returns
Returns datetime representing the end of the week for the given date value, with the offset, if specified.
Examples
The following example returns the end of the week for the specified date.
range offset from -1 to 1 step 1
| project weekEnd = endofweek(datetime(2017-01-01 10:10:17), offset)
Output
| weekEnd |
|---|
| 2016-12-31 23:59:59.9999999 |
| 2017-01-07 23:59:59.9999999 |
| 2017-01-14 23:59:59.9999999 |
The following example returns the end of the week as Sunday for the specified date.
let endofweekSunday = (dateArg: datetime) {
datetime_add('day', 8, endofweek(datetime_add('day', -8, dateArg)))
};
let data=datatable(Date: datetime, day: string)
[
datetime(2025, 6, 14), "Saturday",
datetime(2025, 6, 15), "Sunday",
datetime(2025, 6, 16), "Monday",
datetime(2025, 6, 17), "Tuesday"
];
data
| extend SundayEndOfWeek=endofweekSunday(Date)
Output
| Date | day | SundayEndOfWeek |
|---|---|---|
| 2025-06-14 00:00:00.0000000 | Saturday | 2025-06-15 23:59:59.9999999 |
| 2025-06-15 00:00:00.0000000 | Sunday | 2025-06-15 23:59:59.9999999 |
| 2025-06-16 00:00:00.0000000 | Monday | 2025-06-22 23:59:59.9999999 |
| 2025-06-17 00:00:00.0000000 | Tuesday | 2025-06-22 23:59:59.9999999 |
Related content
- startofweek function
- endofday function
- endofmonth function
- endofyear function
- dayofweek function
- week_of_year function
- ago function
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.