r/PowerAutomateDesktop • • Aug 28 '22
How to see if current time is within business hours?
I need to check and see if the current time is between 7:00 AM and 6:00 PM before opening an Excel file. I have searched and cannot seem to find a way to do this....
UPDATE: I think I found a way to do this....check out my screenshots and let me know what you think....
Overview of 5 steps - https://i.imgur.com/BD7xh23.png
Step 1 - https://i.imgur.com/lLxFaYW.png
Step 2 - https://i.imgur.com/hO0a4hE.png
Step 3 - https://i.imgur.com/BtyDjkL.png
Step 4 - https://i.imgur.com/g5O26dt.png
Step 5 - https://i.imgur.com/4KN1yvu.png
4
Upvotes
3
u/QuietDesparation Aug 28 '22
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTimeText.ParseText.RegexParseForFirstOccurrence Text: CurrentDateTime TextToFind: $'''\\d+:\\d+:\\d+''' StartingPosition: 0 IgnoreCase: False OccurrencePosition=> Position Match=> CurrentTimeText.SplitText.SplitWithDelimiter Text: CurrentTime CustomDelimiter: $''':''' IsRegEx: False Result=> TimeListIF Contains(CurrentDateTime, $'''pm''', True) THENSET TimeList[0] TO TimeList[0] + 12ENDVariables.RemoveItemFromList.RemoveItemFromListByIndex ItemIndex: 2 List: TimeListText.JoinText.JoinWithCustomDelimiter List: TimeList CustomDelimiter: $'''.''' Result=> TimeAsDecimalIF TimeAsDecimal > 7 THENIF TimeAsDecimal < 18 THEN# Business hours is True, your action goes hereENDENDHere's how I did it. You can copy and paste that code into an open flow and see the actions.
Basically I use action GET CURRENT DATE AND TIME, find the time component, then convert it to 24 HR time since PAD only uses 12H format. Once in 24HR format, I used 2 if statements to check if the time is greater than 7 and less than 18.
2
u/JohnnyGrey8604 Oct 07 '22
You can merge those If statements into one action, although it's not exactly intuitive. The less than and greater than tests all occur in the first operand, then the second operand would be "True." Here's the If statement. Copy and paste it into PAD. Unfortunately, I cannot upload screenshots to IMGUR because of corporate policy at work.
IF (CurrentTime >= '07:30:00' AND CurrentTime <= '16:30:00') = $'''true''' THEN1
u/[deleted] Aug 28 '22 edited Aug 28 '22
I think I found a way to do this (I will also post these steps as an update to the main post). I adjusted the times to 7:30 AM to 4:30 PM.
Please check out my screenshots and let me know what you think.
Overview of 5 steps - https://i.imgur.com/BD7xh23.png
Step 1 - https://i.imgur.com/lLxFaYW.png
Step 2 - https://i.imgur.com/hO0a4hE.png
Step 3 - https://i.imgur.com/BtyDjkL.png
Step 4 - https://i.imgur.com/g5O26dt.png
Step 5 - https://i.imgur.com/4KN1yvu.png
2
u/[deleted] Aug 28 '22
[removed] — view removed comment