datetime_local_to_utc()

Applies to: ✅ Azure Data ExplorerAzure MonitorMicrosoft Sentinel

Converts local datetime to UTC datetime using a time-zone specification.

Syntax

datetime_local_to_utc(from,timezone)

Learn more about syntax conventions.

Parameters

Name Type Required Description
from datetime ✔️ The local datetime to convert.
timezone string ✔️ The timezone of the desired datetime. The value must be one of the supported timezones.

Returns

A UTC datetime that corresponds the local datetime in the specified timezone.

Example

datatable(local_dt: datetime, tz: string)
[ datetime(2020-02-02 20:02:20), 'US/Pacific', 
  datetime(2020-02-02 20:02:20), 'America/Chicago', 
  datetime(2020-02-02 20:02:20), 'Europe/Paris']
| extend utc_dt = datetime_local_to_utc(local_dt, tz)

Output

local_dt tz utc_dt
2020-02-02 20:02:20.0000000 Europe/Paris 2020-02-02 19:02:20.0000000
2020-02-02 20:02:20.0000000 America/Chicago 2020-02-03 02:02:20.0000000
2020-02-02 20:02:20.0000000 US/Pacific 2020-02-03 04:02:20.0000000

Note

Normally there is a 1:1 mapping between UTC and local time, however there is a time ambiguity near the DST transition. Translating from local to UTC and then back to local may produce an hour offset between two local datetime values if the clocks were advanced due to DST.

range Local from datetime(2022-03-27 01:00:00.0000000) to datetime(2022-03-27 04:00:00.0000000) step 1h
| extend UTC=datetime_local_to_utc(Local, 'Europe/Brussels')
| extend BackToLocal=datetime_utc_to_local(UTC, 'Europe/Brussels')
| extend diff=Local-BackToLocal
Local UTC BackToLocal diff
2022-03-27 02:00:00.0000000 2022-03-27 00:00:00.0000000 2022-03-27 01:00:00.0000000 01:00:00
2022-03-27 01:00:00.0000000 2022-03-27 00:00:00.0000000 2022-03-27 01:00:00.0000000 00:00:00
2022-03-27 03:00:00.0000000 2022-03-27 01:00:00.0000000 2022-03-27 03:00:00.0000000 00:00:00
2022-03-27 04:00:00.0000000 2022-03-27 02:00:00.0000000 2022-03-27 04:00:00.0000000 00:00:00