June 14, 2024

Power Automate: How to display the day of the week in your language?

Having correct data to show to your users is super important, so today, let’s look at how to display the day of the week in your language. To explain, I’ll use the Portuguese descriptions, but you can edit to use your tongue easily.

There’s a better way to do this and I want to thank Johannes for pointing it out. I wrote an article a few years ago describing how to use the “formatDateTime” function that you can use to achieve this. Also, I wrote another article on the most common formats and how to use them in detail. You can still use this article to learn how to access arrays with variables or customize the day of the week if the one retrieved from Power Automate is not in the format you need.

Let’s check how to display the day of the week in your language.

How to get the day of the week

First, let’s explain how to get the day of the week. We have a function that will help us. It’s called “dayOfWeek,” and it translates any way to a numeric representation from 0 (Sunday) to 6 (Saturday).

Here’s an example with the data of publishing this article (August 1st, 2022).

The result is “2,” meaning “Tuesday.”

Finally, to make it more practical, let’s rename it to “Get the day of the week.”

But a number is not helpful, so let’s transform it to a day of the week.

Create an array with the translation

Now let’s build a translation array. We need to display the information with the day of the week from a number to something people understand. For example, if we have the following array of days of the week:

[
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
]

Let’s build the array (now in Portuguese):

[
"Domingo",
"Segunda-feira",
"Terça-feira",
"Quarta-feira",
"Quinta-feira",
"Sexta-feira",
"Sábado"
]

In Power Automate, we can use the “initialize variable” action like this:

Now that we have a variable, let’s use the index strategy to get the value.

Access the value in the array

Now that we have the day of the week, let’s transform it to a weekday. To do that, we can use Power Automate’s functionality to have an array and provide the index where we want to fetch the information.

We know the first position is a Sunday, so we can access it using its index. The index means the position that we want.

Indexes start always at 0 so if we want position 1 you need to indicate 0 and not 1.

So to access the position, we do:

the_array[index]

The name of the array can be a variable, for example, and the index we already have (the “dayOfWeek” function). And since the variable will return us the values from 0 to 6, we can use it as the index of the array.

Here’s the formula:

variables('DAYS_OF_WEEK')[outputs('Get_the_day_of_the_week')]

As before, we have the variable that contains the array, and we’re using the “Get the day of the week” compose action to get the weekday index.

Here’s the final result:

In Portuguese, “terça-feira” is Tuesday, so it works.

Final thoughts

It seems trivial, but I wanted to explain the “index” part of the strategy in detail since it was fundamental to display the day of the week in your language. The “dayOfWeek” function does most of the heavy lifting, so “translating” that to a valid “day of the week” is super simple as long as you know the formula, of course :).

Have a suggestion of your own or disagree with something I said? Leave a comment or interact on Twitter and check out other Power Automate-related articles here.

Photo by Joel Naren on Unsplash

 

Manuel Gomes

I have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

One thought on “Power Automate: How to display the day of the week in your language?

Leave a Reply

Your email address will not be published. Required fields are marked *