KQL Quickie - Human Readable day of the week

Published July 17, 2024 by FoxDeploy

Ever need to figure out which day of the week something happened, and you’re using an r or ADX like querying language?

Many of these offer a dayofweek function, but in many cases, these will give you a timespan interval since the previous Sunday. I don’t know about you, but for me, it’s very hard to just look at 1.00:00:00 and think “Oh yeah thats a Monday!

Header for this post, reads 'Handing off variables in ADO'

The query

Here is, short and sweet.

let weekday = (day:int) {        
        case(
        day == time(1.00:00:00), "Mon",
        day == time(2.00:00:00), "Tue",
        day == time(3.00:00:00), "Wed",
        day == time(4.00:00:00), "Thu",
        day == time(5.00:00:00), "Fri",
        day == time(6.00:00:00), "Sat",
        "Sun")
    };
    print weekday(1d);   

Result:

Mon

And a full working example

let weekday = (day:int) {        
        case(
        day == time(1.00:00:00), "Mon",
        day == time(2.00:00:00), "Tue",
        day == time(3.00:00:00), "Wed",
        day == time(4.00:00:00), "Thu",
        day == time(5.00:00:00), "Fri",
        day == time(6.00:00:00), "Sat",
        "Sun")
    };    
   range input from 0d to -6d step -1d
   | extend AsDate = ago(input)
   | extend AsWeekDayInt = dayofweek(AsDate)
   | extend AsDayOfWeek = weekday(AsWeekDayInt)

Result:

Header for this post, reads 'Handing off variables in ADO'


Microsoft MVP

Five time Microsoft MVP, and now I work for the mothership


Need Help?

Get help much faster on our new dedicated Subreddit!

depicts a crowd of people in a night club with colored lights and says 'join the foxdeploy subrreddit today'


Blog Series
series_sml_IntroToDsc
series_sml_PowerShellGUI series_sml_IntroToRaspberryPi Programming series_sml_IntroToWindows Remote Management Series The Logo for System Center Configuration Manager is displayed here Depicts a road sign saying 'Learning PowerShell Autocomplete'




Blog Stats