'How to get the minutes from a timespan in KQL
I wanted to extract the time in minutes for a Kusto query I was working on. I have a cloumn where timespan is represented in the following format (HH:MM:SS.MilliSeconds) 01:18:54.0637555. I wanted to extract the number of minutes from this in this case 78 minutes. How can I do that ?
Solution 1:[1]
Try dividing the timespan value by 1min, as explained here: https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datetime-timespan-arithmetic
Solution 2:[2]
If you just need to print the timespan parts, you can create a small user-defined function to collect each part of the timespan:
let print_timespan = (input: timespan) {
iif(
isempty(input), "",
strcat(
format_timespan(input, 'dd'), "d ",
format_timespan(input, 'hh'), "h ",
format_timespan(input, 'mm'), "m ",
format_timespan(input, 'ss'), "s ")
)
};
let t = time(29.09:00:05.12345);
print print_timespan(t)
---
29d 09h 00m 05s
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yoni L. |
| Solution 2 |
