diff --git a/data-explorer/kusto/query/endofweek-function.md b/data-explorer/kusto/query/endofweek-function.md index c45bf09e26..f018344d56 100644 --- a/data-explorer/kusto/query/endofweek-function.md +++ b/data-explorer/kusto/query/endofweek-function.md @@ -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"] +> Run the query +::: 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) diff --git a/data-explorer/kusto/query/startofweek-function.md b/data-explorer/kusto/query/startofweek-function.md index 110b39c894..f047315513 100644 --- a/data-explorer/kusto/query/startofweek-function.md +++ b/data-explorer/kusto/query/startofweek-function.md @@ -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"] @@ -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"] +> Run the query +::: 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) \ No newline at end of file +* [ago function](./ago-function.md) +* [bin function](./bin-function.md) \ No newline at end of file