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.

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'm a previous Project Manager, and Developer now focused on delivering quality articles and projects here on the site. I've worked in the past for companies like Bayer, Sybase (now SAP), and Pestana Hotel Group and using that knowledge to help you automate your daily tasks

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.