Is it possible to change the day returned from startofweek() and endofweek()?
Asked Answered
T

3

7

Kusto provides functions to get the start- and end-day of the week. These are invoked through startofweek() and endofweek(). startofweek() returns Sunday, and endofweek() returns Saturday.

In some countries, weeks are from Monday to Sunday, which I have been unable to locate how to change.

Is it possible to set the culture in kusto, such that startofweek() and endofweek() would return Monday and Sunday respectively?

Thickhead answered 12/6, 2020 at 10:43 Comment(0)
S
7

No, I have not seen a setting where culture can be set in Kusto. Where operating systems and applications which make it possible to set such configurations, I see Kusto being being fairly basic and similar to .NET libraries where the DayOfWeek enum begins with Sunday at index 0 and there is no way to change that foundation.

The documentation indicates that "Start of the week is considered to be a Sunday." so I believe that is that. It is up to us users to adapt from there. (https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/startofweekfunction)

I'm sure you have done this yourself already, but here has been my approach.

startofweek(now()) + 1d
endofweek(now()) + 1d
Snick answered 25/6, 2020 at 19:27 Comment(2)
Thank you the response. I suspected this might be the case. I did end up with a solution similar to what you suggested!Thickhead
@Snick You need to test for Sundays (with dayofweek(now()) == 0d) in a case() or an iff() and substract 6d if it's Sunday: startofweek(now()) - 6d and endofweek(now()) -6dDuarte
F
0

This will return Monday as the start of the week:

iff(dayofweek(now()) == 0, startofweek(now()) - 6d, startofweek(now()) + 1d)

This will return Sunday as the end of the week:

iff(dayofweek(now()) == 0, endofweek(now()) - 6d, endofweek(now()) + 1d)
Forworn answered 31/1, 2024 at 11:30 Comment(1)
Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?Crock
D
0

This achieves the same effect with better logical & semantic compaction:

StartOfWeekMonday = startofweek(now() - 1d) + 1d
Dinadinah answered 4/10, 2024 at 16:58 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.