cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bitshift
Regular Visitor

How to get numeric day of week from date

Given a Date or DateTime,  the DayOfWeek property gives a text value eg. Friday, whereas I need the integer value.  Where is that?
What Im trying to do is get the Sunday date for the current week, so I supposed it would be:
CurrentDate - DayOfWeek

help?

12 REPLIES 12
ScottShearer
Super User
Super User

@bitshift 

dayOfWeek() actually does return an integer.  Sunday is 0 and Saturday is 6

image.pngimage.png

If you are looking for the previous Sunday, see my example below:

image.pngimage.png

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
bitshift
Regular Visitor

Sorry I wasnt clear, this is regarding PAD - power automate desktop
Datatype properties - Power Automate | Microsoft Docs

 

Dates

DATESProperty Description
YearThe year part of the datetime value.
MonthThe month part of the datetime value.
DayThe day part of the datetime value.
DayOfWeekThe name of the day (Sunday, Monday etch).
DayOfYearThe day of the year part of the datetime value (1-365/6).
HourThe hour part of the datetime value.
MinuteThe minute part of the datetime value.
Second

The seconds part of the datetime value.

 

bitshift_0-1639166343385.png

 

MichaelAnnis
Super User
Super User

Do you need Power Automate Desktop or Power Automate, like @ScottShearer is using?

I would use a Switch:

 

Switch %dayofweek%
Case “Sunday”, %result% = 1

Case “Monday”, %result% = 2
and so on

End (Switch)

bitshift
Regular Visitor

Why is there a difference between power automate cloud and desktop, or am i missing something?

Here is some input from other users:  https://powerusers.microsoft.com/t5/General-Power-Automate/Power-Automate-Cloud-vs-Desktop/td-p/7924...

 

Personally, I think PAD is easier to use, bot the online version has more capability, such as triggers being able to occur from online activity.  Ex. it taps into your outlook and says "when I receive an e-mail from so-and-so, do this."

In PAD, you would have to trigger the flow manually (or schedule a flow to run systematically), and you could say, "check all unread messages for an e-mail from so-and-so, and do this."

 

So, PAD is a little limited in that manner.  I think the best is to learn both.  PAD might be better to learn first to take care of your local processes on your own workstation.

bitshift
Regular Visitor

I was able to accomplish what I needed with a switch.  What a pain!  Would be nice to have the numeric value available from DayOfWeek or something similar

bitshift_0-1639169789718.pngbitshift_1-1639169830966.png

 

You might find this interesting too; it was for "last Friday", but you could easily change that to "last Sunday", if you always need last Sunday's date.

 

https://powerusers.microsoft.com/t5/Power-Automate-Desktop/Append-Text-to-File-Name-in-Save-As-box/m...

 

There are many ways to accomplish this, and one is using the power of Powershell.
You can feed the "run powershell scupt" with any date and get the weeknumber.
Dateformat to feed the powershell script is MM/dd/yyyy

Highboy_1-1639179530815.png

 

 

AlexScharpé
Frequent Visitor

I am currently experiencing the same problem in PAD where I need to find the numeric week we are in. An out of the box solution I might go for is to visit a website like https://www.epochconverter.com/weeknumbers and spy the week number as a UI element. You could try the same with the day number..

Get Current Date Time

Date to Text Custom format 01/01/yyyy to %BDTY_mmddyyyy_Slash% (stands for beginning day this year)

Text to Date %BDTY_mmddyyyy_Slash% custom format mm/dd/yyyy to %BDTY%

Subtract Dates (CurrentDateTime -  %BDTY%) to %Days% 'days in this year'

Set %Weeks_frac% to %Days / 7%

Truncate number %Weeks_frac% using Get integer part to %Weeks_rounddown%

Set %CurrentWeek% to %Weeks_rounddown + 1%

 

So, this will work depending on how you want to calculate the first week of the year, if 01/01 to 01/07 is the first week, then this will do.  If you want your week to start on a Monday, and any portion of the beginning of the year still counts as the first week, then I would pick the first Monday before 1/1, and change the second line:

 

from:  Date to Text Custom format 01/01/yyyy to %BDTY_mmddyyyy_Slash% (stands for beginning day this year)

to:  Set %BDTY_mmddyyyy_Slash% to 12/27/2021

 

Note:  as it stands here, you will have to change that start date each year if you choose this path, or figure out a new logic to define the first Monday before the first of the year.  It can be done, but it's a little more involved.

AlexScharpé
Frequent Visitor

AlexScharp_0-1642606171758.png

Just found out about a more straightforward solution to get the current day:

1) Use the 'Get current date and time" action

2) Set a variable which retrieves the "Day Of Week" on the first action's variable

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Top Solution Authors
Top Kudoed Authors
Users online (1,395)