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

时间:2020-02-25 22:49:42

标签: kusto kusto-query-language

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

enter image description here

这是我到目前为止所能完成的工作,但是应该有更好的方法来做到这一点。 任何人都可以让我知道是否可以改善此查询? 开始当前月份的常见做法是什么?

下面,获取年份和月份,如果需要月份,则添加前导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);

2 个答案:

答案 0 :(得分:3)

尝试使用startofmonth()函数。

示例:

MyKustoTable 
| project MonthStart = startofmonth(datetime('2020-2-5')) 

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

答案 1 :(得分:1)

相关问题