如何在 Kusto 查询中排除周末?

How to exclude weekends in Kusto query?

有没有办法使用现有的 Kusto 命令排除两个日期之间的周末?我在这里找不到合适的函数 https://kusto.azurewebsites.net/docs/queryLanguage/query-essentials/readme.html

您可以使用 | where dayofweek(timestamp) < 6 从查询中排除周六和周日。请参考dayofweek() doc.

我认为 Dmitry 的评论可能已过时,因为它不起作用。第 0 个索引代表星期日,第 6 个索引代表星期六。排除周末的更具体的工作示例如下:

| where dayofweek(Timestamp) != time(6.00:00:00)
| where dayofweek(Timestamp) != time(0.00:00:00)

如果需要可以进一步压缩。

来自 Void.Massive 答案。

为了提高可读性,我刚刚为 Saturday/Sunday 创建了变量,因为我不经常使用这个逻辑,或者如果我要分享,我想让这个逻辑在 reader.

let Saturday = time(6.00:00:00);
let Sunday = time(0.00:00:00);
//
| where dayofweek(Timestamp) != Saturday
| where dayofweek(Timestamp) != Sunday

另一种选择是进行 !in 检查。

let T = datatable(timestamp: datetime)
[
   datetime("2022-04-03"), // Sunday
   datetime("2022-04-04"), // Monday
   datetime("2022-04-05"), // Tuesday
   datetime("2022-04-06"), // Wednesday
   datetime("2022-04-07"), // Thursday
   datetime("2022-04-08"), // Friday
   datetime("2022-04-09"), // Saturday
   datetime("2022-04-10"), // Sunday
];
T 
// 0d = Sunday, 6d = Saturday
| where dayofweek(timestamp) !in (0d, 6d)