Home > OS >  Custom date format in KQL
Custom date format in KQL

Time:02-17

I would like to know if there is a possibility to customize the format of a specific datetime in KQL.

For example I have the following code:

let value = format_datetime(datetime(07:30:00), "HH:mm");
print value

As a result we obtain 07:30

My question here is that instead of having 07:30, is there a possibility to format it in a way to have a value = 7hr 30m

CodePudding user response:

based on if your input is a datetime or a timespan value, you can try either of the following options (using some string manipulation):

print ts = timespan(07:30:00)
| project output = strcat(toint(ts/1h), "hr ", toint(ts/1m)`, "min")

print dt = datetime(2021-02-16 07:30:00)
| project output = strcat(datetime_part("hour", dt), "hr ", datetime_part("minute", dt), "min")
  • Related