Skip to content

Commit

Permalink
adding new post, kql human readable day of the week
Browse files Browse the repository at this point in the history
  • Loading branch information
stowen-msft committed Jul 18, 2024
1 parent c9a4db1 commit 5597d1d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions _posts/2024-07-17-kql-quickie-human-readable-day-of-week.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: "KQL Quickie - Human Readable day of the week"
date: "2024-07-17"
redirect_from : 2024/07/17/kql-quickie-human-readable-day-of-week
coverImage: \assets\images\2024\kqlHumanReadable.webp
categories:
- "querying"
tags:
- "queries"
- "kusto"
excerpt: "Have you ever needed to do complex automation in Azure Devops? Like retrieving a token for one service and handing it off to subsequent commands to use? Then you might have been puzzled about the correct syntax to use. In this post, I'll give you a working example of how the syntax should be used to hand variables between bash and PowerShell tasks in Azure Devops"
fileName: '2024-06-16-how-to-pass-variables-between-azure-devops-bash-and-powershell-commands'
---
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'](\assets\images\2024\kqlHumanReadable.webp)

## The query

Here is, short and sweet.

```kql
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

```kql
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'](\assets\images\2024\weekDayResults.png)
Binary file added assets/images/2024/kqlHumanReadable.webp
Binary file not shown.
Binary file added assets/images/2024/weekDayResults.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5597d1d

Please sign in to comment.