Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions data-explorer/kusto/query/endofweek-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,37 @@ The following example returns the end of the week for the specified date.
|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.

:::moniker range="azure-data-explorer"
> [!div class="nextstepaction"]
> <a href="https://dataexplorer.azure.com/clusters/help/databases/Samples?query=H4sIAAAAAAAAA3XQzwuCMBQH8Pv%2BikcXN1hQ0i8UD0Edo4NBh4hY7CmSKeikpPrfe7NECNth7Mdn7%2FFdigYw03l0Q7yEVaZVDQFwrQwui9gDuzDJFQU8GNBo9yelNXdIOxLGsivB%2B8BwIeFbUQjBXj5LqS2dqMBORp1T5CsCXT%2F7oPagNEWSxYIdWHvB3ZE7lTCjthMhYRAqUxVkB7KPTBvSxOoHMws2%2BX8wt2BXYWkFO%2FrWKGBPwLuh1PApvs70NtpT%2FuDnM5tY4g0tAMSOZgEAAA%3D%3D" target="_blank">Run the query</a>
::: moniker-end

```kusto
let endofweekSunday = (dateArg: datetime) {
datetime_add('day', 1, 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-08 23:59:59.9999999|
|2025-06-15 00:00:00.0000000|Sunday|2025-06-08 23:59:59.9999999|
|2025-06-16 00:00:00.0000000|Monday|2025-06-15 23:59:59.9999999|
|2025-06-17 00:00:00.0000000|Tuesday|2025-06-15 23:59:59.9999999|

## Related content

* [startofweek function](./startofweek-function.md)
Expand Down
36 changes: 34 additions & 2 deletions data-explorer/kusto/query/startofweek-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Start of the week is considered to be a Sunday.

A datetime representing the start of the week for the given *date* value, with the offset, if specified.

## Example
## Examples

:::moniker range="azure-data-explorer"
> [!div class="nextstepaction"]
Expand All @@ -50,9 +50,41 @@ range offset from -1 to 1 step 1
|2017-01-01 00:00:00.0000000|
|2017-01-08 00:00:00.0000000|

The following example returns the start of the week as Monday for the specified date.

:::moniker range="azure-data-explorer"
> [!div class="nextstepaction"]
> <a href="https://dataexplorer.azure.com/clusters/help/databases/Samples?query=H4sIAAAAAAAAA3XQwQrCMAwA0Hu%2FIuxiCxV0uAmTHQTx5knBg4hUGsdwdlA7dKj%2Fbro59DB7KE37kpAW6ODqlHXl6YZ4XtrysiqNVjWkwLVyOLdZAv7g8gsKeDCg1cUHpTUfkB5IGMvfQryPDMl8agoh2GvGCmpPNyr1m1PHAvmCwLejT6gTqmxzkwm2Y90DD0dhJCGmxhMhIVgrV1mygewjUUMq8xfEHrST94OpB5sKr16w%2FcwbBewJeHdoNLS5Wxo97f3PZi7xBi07C4NvAQAA" target="_blank">Run the query</a>
::: moniker-end

```kusto
let startofweekFromMonday = (dateArg: datetime) {
datetime_add('day', 1, startofweek(datetime_add('day', -1, 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 MondayWeek=startofweekFromMonday(Date)
```

**Output**

|Date|day|MondayWeek|
|---|---|---|
|2025-06-14 00:00:00.0000000|Saturday|2025-06-09 00:00:00.0000000|
|2025-06-15 00:00:00.0000000|Sunday|2025-06-09 00:00:00.0000000|
|2025-06-16 00:00:00.0000000|Monday|2025-06-16 00:00:00.0000000|
|2025-06-17 00:00:00.0000000|Tuesday|2025-06-16 00:00:00.0000000|

## Related content

* [dayofweek function](./day-of-week-function.md)
* [endofweek function](./endofweek-function.md)
* [week_of_year function](./week-of-year-function.md)
* [ago function](./ago-function.md)
* [ago function](./ago-function.md)
* [bin function](./bin-function.md)