Get the day of the week
Power Automate Desktop has several data types internally, although they aren’t shown explicitly when you configure actions, so users don’t need to think about them.
This article explains how to use one of them, the Datetime type, to get the day of the week.
About the Datetime type
Section titled “About the Datetime type”The Datetime type, which you can create with actions such as “Get current date and time,” has several properties, listed below.
| Property | Meaning |
|---|---|
| Year | Year (number) |
| Month | Month (number) |
| Day | Day (number) |
| DayOfWeek | Day of the week (string) |
| DayOfYear | Day of the year (January 1 is 1; number) |
| Hour | Hour (number) |
| Minute | Minute (number) |
| Second | Second (number) |
You can get each property with %VariableName.PropertyName%. If the variable name is CurrentDate, for example, you specify %CurrentDate.Year%.
By getting DayOfWeek from these properties, you can get the day of the week.
The string is returned in English, for example “Friday” for Friday and “Sunday” for Sunday.
Implement by copying and pasting
Section titled “Implement by copying and pasting”Copy the following code and paste it into the Power Automate Desktop flow designer to add the actions.
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTimeSET Day TO CurrentDateTime.DayOfWeekImplement in Power Automate Desktop
Section titled “Implement in Power Automate Desktop”-
In “Search actions,” type “Get current date,” and use the “Get current date and time” action to create a Datetime variable (CurrentDateTime).
-
In “Search actions,” type “Set variable” and set the following parameters.
Parameter Value Variable Day Value %CurrentDateTime.DayOfWeek% -
When you run the flow, the day of the week is set in the variable “Day.”
Possible exceptions
Section titled “Possible exceptions”The “Set variable” action never throws an exception (error), so you don’t need any error handling.