Sep 05 2022 06:11 AM
In Azure Log Analytics Queries, is there a way to parse ISO 8601 durations to use in comparisons? The format looks like this: PT1H29M58.163977013S
Sep 05 2022 10:07 AM
I did start to write a function for this, but never went back to it, here is where I got to (limited testing but maybe it will give you or others an idea). It only deals with D,T,H and in a basic way.
let a = "PD1T1H29M58.163977013S";
// use Usage as it always exists
Usage
| extend d = extract("D([0-9]+)",1,a, typeof(real)) * 1440 //convert mins
| extend h = extract("T([0-9]+)",1,a, typeof(real)) * 60 //convert hours to mins
| extend m = extract("H([0-9]+)",1,a, typeof(real))
| extend newDay_ = strcat(d + h + m,"m")
| where TimeGenerated > ago(totimespan(newDay_))
| project-away d,h,m
Sep 08 2022 06:59 AM