Reputation: 361
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 = datetime(2022-06-08); print Date = value
As a result I get: 2022-06-08 00:00:00
My question here is that instead of having 2022-06-08 00:00:00, is there a possibility to format it in a way to have the Date = 8 June 2022
Upvotes: 1
Views: 1562
Reputation: 946
With the supported formats you can do stuff like this:
let dt = datetime(2017-01-29 09:00:05);
print
v1=format_datetime(dt,'yy-MM-dd [HH:mm:ss]'),
v2=format_datetime(dt, 'yyyy-M-dd [H:mm:ss]'),
v3=format_datetime(dt, 'yy-MM-dd [hh:mm:ss tt]')
However the month of year is supported only as numeric values in datetimes.
Maybe run case() in order to get June, July etc
let GetMonth = view(Month:int){
case(
Month==1, "January",
Month==2, "February",
Month==3, "March",
Month==4, "April",
Month==5, "May",
Month==6, "June",
Month==7, "July",
Month==8, "August",
Month==9, "September",
Month==10, "October",
Month==11, "November",
Month==12, "December"
)};
let x = datetime(2017-01-29 09:00:05);
let month = monthofyear(x);
print strcat(
dayofmonth(x), " ",
GetMonth(monthofyear(x)), " ",
datetime_part("Year", x))
Upvotes: 1