Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Custom date format in KQL

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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)%60, "min")

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading