I have millions of records in Azure Data Explorer. Each of this record has a timestamp value associated with it. I want to be able to convert this timestamp value in the specific time zone.
For example in SQL I use AT TIME ZONE to convert timestamp value from one zone into another –
Select CONVERT(datetime, timestampvalueColumn) AT TIME ZONE 'UTC' AT TIME ZONE 'US Eastern Standard Time' as 'TimeInEST' from Table;
I am not willing to use offset value as it doesn’t support daylight saving changes.
How I can do this with Kusto query language in ADX?
3
Answers
Usually the answer is "Don’t do it in Kusto", do it in the client that is reading the results from Kusto, which most certainly will have a "utc-to-local-time" or "utc-to-this-timezone" functions.
Well, the Kusto team is moving fast 🙂
Support for timezones conversion has been added:
Fiddle
You can build a convenience function using a similar ideia of the function given bellow. Note that the conversion works for DST (Daylight Saving Time) as well. You just need a way to map a place to its timezone string. In the function that follows, the mapping is from a Brazilian state abbreviation to its timezone string.
See the documentation for a list of available timezones.
A couple tests at the moment when DST ended in the
DF
Brazilian state:print(ToLocalDatetime('DF', datetime('2019-02-17 01:00:00')))
Output:
2019-02-16T23:00:00-02:00
print(ToLocalDatetime('DF', datetime('2019-02-17 02:00:00')))
Outputs
2019-02-16T23:00:00-03:00
I agree with other answers stating that is better to do it on the client side for most cases. Additionally, the
iff
sequence of the function is ugly. For a more elegant solution, it is possible to define a datatable such as:However, if you to it you cannot use the function on some scenarios, due to documented restrictions.