Share via

KQL query pass current time

Madhu Rao 160 Reputation points
2024-08-14T03:37:45.1533333+00:00

I have a requirement to capture changes done between two timeframes. I have powershell script that selects the $starttime and $endtime based on the script start time.

$startTime = "08:30:00"

$endTime = "11:30:00"

$queryChangeAn = @"

resourcechanges

| extend changeTime = todatetime(properties.changeAttributes.timestamp),

| where changeTime between (datetime($startTime) .. datetime($endTime))

| project changeTime, changedBy, properties, ['id'], name, tenantId, resourceGroup, subscriptionId,correlationId

"@

How do I pass the local time starttime and endtime? to KQL. I believe it is converting it to UTC.

Azure Monitor
Azure Monitor

An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.

0 comments No comments

Answer accepted by question author

Stanislav Zhelyazkov 29,586 Reputation points MVP Volunteer Moderator
2024-08-14T06:01:34.9333333+00:00

Hi,

You can convert the time from utc to any timezone you desire via datetime_utc_to_local() function.

$startTime = "08:30:00"

$endTime = "11:30:00"

$queryChangeAn = @"

resourcechanges

| extend changeTime = datetime_utc_to_local(todatetime(properties.changeAttributes.timestamp),'America/Argentina/Salta'),

| where changeTime between (datetime($startTime) .. datetime($endTime))

| project changeTime, changedBy, properties, ['id'], name, tenantId, resourceGroup, subscriptionId,correlationId

"@

Note that you need to convert the time of the change to your local time and the dates you provided will be in local time already.

Other option is to convert your time inputs into utc and than you will not have to use datetime_utc_to_local() for the changeTime.

Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.