Kusto 查询 - 如何获取当月的开始日期时间

mas*_*san 1 kql azure-data-explorer

学习 Kusto 查询并寻找一种获取当月日期时间开始的方法。截至我发布此内容时,时间为 2020 年 2 月 25 日,因此输出应如下所示,代表 2020 年 2 月 1 日

在此输入图像描述

这是我到目前为止所拥有的并且有效的方法,但是应该有更好的方法来做到这一点。谁能告诉我这个查询是否可以改进?获取当月月初的常见做法是什么?

下面,获取年份和月份,如果需要月份,则添加前导 0,然后连接字符串并分配给变量“d”,该变量看起来像“2020-02-01”,并将该字符串传递给 todatetime()

let year = datetime_part("Year",now());
let month = datetime_part("Month",now());
let m = case(month < 10, strcat("0", month), tostring(month));
let d = strcat(year, "-", m, "-01" );
print todatetime(d);
Run Code Online (Sandbox Code Playgroud)

an1*_*que 5

尝试该startofmonth()功能。

例子:

MyKustoTable 
| project MonthStart = startofmonth(datetime('2020-2-5')) 
Run Code Online (Sandbox Code Playgroud)

参考: https: //learn.microsoft.com/en-us/azure/kusto/query/startofmonthfunction