Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding offset to datetime values in Kusto

How do we add time offsets to datetime value in Kusto? As an example, I have table with the time in UTC and offset values.

utcStartDateTime        uctOffset
2020-04-16T00:00:25Z    08:00:00
2020-04-16T00:00:47Z    10:00:00

I would like to add them. I tried the below with no luck.

datetime_add('hour',datetime_part('hour', todatetime(utcOffset)),todatetime(utcStartDateTime))

The below works but it is good for only hourly offsets.

 datetime_add('hour', toint(split(utcOffset, ":" )[0]),todatetime(utcStartDateTime))
like image 212
madjazz Avatar asked Nov 18 '25 09:11

madjazz


1 Answers

Ideally, datetime values would be typed as datetime, and timespan values would be typed as timespan, and then you can simply add them

the following example assumes the worst, i.e. both your columns are typed as string (based on how you attempted to solve it in your original question)

datatable(utcStartDateTime:string, uctOffset:string)
[
    '2020-04-16T00:00:25Z', '08:00:00',
    '2020-04-16T00:00:47Z', '10:00:00'
]
| extend date_with_offset = todatetime(utcStartDateTime) + totimespan(uctOffset)
like image 185
Yoni L. Avatar answered Nov 21 '25 09:11

Yoni L.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!