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" ]
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.
So to access the position, we do:
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:
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.
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 :).