Vaibhav Garg
Vaibhav Garg

Reputation: 137

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 ?

Upvotes: 11

Views: 14534

Answers (2)

Mário Meyrelles
Mário Meyrelles

Reputation: 1792

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 

Upvotes: 1

Yoni L.
Yoni L.

Reputation: 25895

Try dividing the timespan value by 1min, as explained here: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/datetime-timespan-arithmetic

Upvotes: 13

Related Questions