KQL 帮助:需要 trim 日期时间值

KQL Help: Need to trim the Datetime value

我需要 trim KQL 中的日期时间值。

我有基于 Timer Trigger 的 Azure 功能,每 30 分钟运行一次

("0 */30 * * * *")]

我有 2 个日期时间列 StartTimeEndTime。我通过总结 min(StartTime) - max(EndTime) 来获取 Azure 函数的运行时。 我希望 min(StartTime) 到 trimmed 到 Azure 函数的实际开始时间。

示例:如果 min(StartTime) 列值为“2021-10-25 10:02:26.7630995”,则 StartTime 应为“2021-10- 25 10:00:00.000000

如果 min(StartTime) 列值为“2021-10-25 10:32:26.7630995”,则 StartTime 应为 “2021 -10-25 10:30:00.000000

到目前为止我的代码:(我需要第 4 行的帮助)

MyKustoTable | where isnotempty(RunID) and RunID > 41
| project RunID, CollectionTime, IngestionTime = ingestion_time()-30m
| summarize StartTime = min(CollectionTime), EndTime = max(IngestionTime) by RunID
| extend RBACDurationInMins = case((EndTime - StartTime)/1m > 30, "Trimmed StartTime", StartTime) 
| extend RBACDurationInMins = (EndTime - StartTime)/1m, ResourceType = "RBAC"
| project ResourceType, RunID, StartTime, EndTime, RBACDurationInMins
| sort by RunID desc

您可以使用 bin() 函数:https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/binfunction

if the min(StartTime) Column Value is "2021-10-25 10:02:26.7630995" then the StartTime should be "2021-10-25 10:00:00.000000"

If the min(StartTime) Column Value is "2021-10-25 10:32:26.7630995" then the StartTime should be "2021-10-25 10:30:00.000000"

print dt1 = datetime(2021-10-25 10:02:26.7630995), 
      dt2 = datetime(2021-10-25 10:32:26.7630995)
| project result1 = bin(dt1, 30m),
          result2 = bin(dt2, 30m)
result1 result2
2021-10-25 10:00:00.0000000 2021-10-25 10:30:00.0000000