Convert UTC 'TimeGenerated' to local time in Azure monitor/log/analytics, when using "summarize by"
Asked Answered
E

4

8

I have this simple query

MyLog
| summarize  avg(executionTimeInMS_d) by bin(TimeGenerated, 5min)

I'd like the summary to be in my local time zone, not UTC. This does not work :

MyLog
| summarize  avg(executionTimeInMS_d) by bin(TimeGenerated-5, 5min)

Can this be done?

Ese answered 18/12, 2019 at 13:48 Comment(0)
H
5

There is now a "Display time zone" setting in the App Insights query page. This will convert the timestamp to the selected timezone. It will also show the timezone in the timestamp column heading.

This only seems to work if you output the timestamp directly. If you apply any operations it reverts to UTC.

Herrmann answered 23/1, 2022 at 1:35 Comment(0)
H
4

datetime values are in UTC.

if you know the timezone offset (at the time you run the query), you can subtract/add it to your datetime values as explained here: https://learn.microsoft.com/en-us/azure/kusto/query/datetime-timespan-arithmetic

for example: print now() - 7h

Hanshansard answered 18/12, 2019 at 15:56 Comment(0)
G
4

Best to convert using the datetime_utc_to_local() function. This way you can dynamically handle daylight savings within the query and don't need to depend on the UI.

AzureDiagnostics
| extend CentralTime = datetime_utc_to_local(TimeGenerated, "US/Central")
Gossipry answered 2/9, 2022 at 22:24 Comment(1)
In Application Insights, I thought this function wasn't supported because the editor showed an error, "The name 'datetime_utc_to_local' does not refer to any known function." Turns out it is supported when you run a query though. For example: TimeLocal = datetime_utc_to_local(timestamp, "America/Los_Angeles"). Not perfectly supported, as the column name output for the above projection is TimeLocal [UTC], but I'll live.Chiekochien
D
0

You can do this by subtracting/adding the time different from UTC. For example, to convert to EST. I subtracted 5h from TimeGenerated which is in UTC.

AppServiceConsoleLogs
| extend EasternTime = TimeGenerated - 5h
| sort by EasternTime desc
| project Level, EasternTime, ResultDescription
Demp answered 15/1, 2023 at 7:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.