【问题标题】:Kusto query - how to get beginning datetime of current monthKusto 查询 - 如何获取当月的开始日期时间
【发布时间】:2020-02-25 22:49:42
【问题描述】:

学习 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);

【问题讨论】:

    标签: azure-data-explorer kql


    【解决方案1】:

    试试startofmonth() 函数。

    例子:

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

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

    【讨论】:

    • 我将该函数用于其他查询,但它只返回当前月份的 int,即“2”,但我正在寻找一种获取日期时间的方法
    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 2014-05-29
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-01
      相关资源
      最近更新 更多