Search code examples
azure-data-explorerkql

Kusto Query to extract mmm-yyyy from timestamp column


I have a timestamp column with datetime values. I want to extract year-month from it. For Example: if timestamp is 2020-02-19T13:42:51.393Z, output I want is Feb-2020.

I tried looking at https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/format-datetimefunction, it has nothing for month.

Thanks in advance.


Solution

  • you could try something like this:

    let months = dynamic({"1":"Jan", "2":"Feb", "3":"Mar","4":"Apr","5":"May","6":"Jun","7":"Jul","8":"Aug","9":"Sep","10":"Oct","11":"Nov","12":"Dec"});
    print dt = datetime(2020-02-19T13:42:51.393Z)
    | project s = strcat(months[tostring(getmonth(dt))], "-", getyear(dt))