3

How can I convert time difference into milliseconds in Azure Application Insights

let startTime = todatetime('2017-05-15T17:02:23.7148691Z');
let endTime = todatetime('2017-05-15T17:02:25.5430172Z');
let timeDifference = endTime-startTime;
requests
| project timeDifference
| limit 1

The above query outputs

00:00:01.8281481

I would like to display it in milliseconds

For ex: 1828

Praveen Reddy
  • 7,295
  • 2
  • 21
  • 43

2 Answers2

3

You can divide your timespan by another timespan. So, to get number of milliseconds you can do the following:

let startTime = todatetime('2017-05-15T17:02:23.7148691Z');
let endTime = todatetime('2017-05-15T17:02:25.5430172Z');
let timeDifference = endTime-startTime;
// get total milliseconds 
requests
| extend timeDifferenceMilliseconds = timeDifference / time(1ms)
| project timeDifferenceMilliseconds
| limit 1

More about date and time expressions can be found here: https://learn.microsoft.com/en-us/azure/application-insights/app-insights-analytics-reference#date-and-time-expressions

ZakiMa
  • 5,637
  • 1
  • 24
  • 48
1

Another solution is to use the built-in datetime_diff function and specify milliseconds:

let startTime = todatetime('2017-05-15T17:02:23.7148691Z');
let endTime = todatetime('2017-05-15T17:02:25.5430172Z');
let timeDifference = datetime_diff("Millisecond", endTime, startTime);
requests
| project timeDifference
| limit 1

Documentation is here: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/datetime-difffunction

Zeph
  • 64
  • 6