MaxDev
MaxDev

Reputation: 147

format_datetime() in Kusto for datetime with minutes and secounds as 00

In the azure data explorer documentation, there is a lot of supported formats but not the one that i am looking for.

What I need is to format the datetime like "yyyy-MM-dd HH" to set the minutes and seconds as 0

Input datetime

2020-04-21T17:44:27.6825985Z

expected results

2020-04-21 17:00:00

Upvotes: 3

Views: 15439

Answers (2)

Yoni L.
Yoni L.

Reputation: 25895

you can use bin() to round down to the hour, and if you still need to remove the datetime parts lower than seconds, you can use substring() (or format_datetime()). e.g.:

print d = datetime(2020-04-21T17:44:27.6825985Z)
| extend h = bin(d, 1h)
| extend h2 = substring(h, 0, 19)

Upvotes: 4

sowen
sowen

Reputation: 1088

hmm, if you always just want the rest to be 0, can you just use string concatenation?

let d = datetime(2020-04-21T17:44:27.6825985Z);
print strcat(format_datetime(d, "yyyy-MM-dd HH"), ":00:00")

the above code will give you the result of

2020-04-21 17:00:00

Upvotes: 3

Related Questions