As part of a PAD flow, I'd like to be able to populate a date field with the date of the next upcoming Saturday. For example, if today is Thursday 10/19/23, I'd like to have PAD input 10/21/23. Would need a solution that would work regardless of current day of week.
Thanks for any help!
Finally got a minute to try this... and it's INCREDIBLE! Love the simplicity of the solution... Thank you!
Thank you!
Hello @Murphys110
Sharing one more easy method for next date calculation using .Net Run script action see below
Inside of .Net run script action
Code used
output_date= CDate(input_date).AddDays(6-Cint(CDate(input_date).DayOfWeek)).ToString("dd\/MM\/yyyy")
The output is
which is next satuday's date.
Hope this helps !
Nived N 🚀
LinkedIn: Nived N's LinkedIn
YouTube: Nived N's YouTube Channel
🔍 Found my answer helpful? Please consider marking it as the solution!
Your appreciation keeps me motivated. Thank you! 🙌
Many thanks! Will try that as well!
An alternative method to what @MichaelAnnis suggested is using the .DayOfWeek property of a date time variable.
You can build a loop that increases your current date by 1 day and then checks the .DayOfWeek property of the resulting day. If it is equal to Saturday, you can exit the loop.
It would look like this:
Here's a snippet you can paste into PAD:
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
LOOP WHILE (CurrentDateTime.DayOfWeek) <> ($'''Saturday''')
DateTime.Add DateTime: CurrentDateTime TimeToAdd: 1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> CurrentDateTime
END
Please note that the value of the .DayOfWeek property is localized. So, if your PAD is not English, you need to translate the "Saturday" in the loop to the appropriate name of the day in your language.
When the loop is done, your %CurrentDateTime% variable will hold the next Saturday.
You can also have a separate variable, if you don't want to overwrite %CurrentDateTime%, by adding a single Set variable action before the loop. I just wanted to show you how it can be done with as few actions as possible.
-------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.
Wow! I'm off for a couple of days, so will be next week before I can try this out, but thank you! For now I've got it set where I'll just run it on the same day each week, so adding days will be easy... But I much prefer the flexibility your code should provide!
This is a lot, but basically, we establish a known Saturday and then it does a bunch of math to use that known Saturday to find the next Saturday. I subtract today from the known Saturday to get the days, divide by 7 to get the weeks, truncate that to get just the number of weeks, add 1 so it pushes it to the next Saturday (in weeks), and then add those weeks back to the Known Saturday. It's good times...code attached (if you aren't familiar, you can copy and paste this code directly in:
SET KnownSat_mmddyyyy_Slash TO $'''09/30/2023'''
Text.ConvertTextToDateTime.ToDateTimeCustomFormat Text: KnownSat_mmddyyyy_Slash CustomFormat: $'''MM/dd/yyyy''' DateTime=> KnownSat_Date
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
DateTime.Subtract FromDate: CurrentDateTime SubstractDate: KnownSat_Date TimeUnit: DateTime.DifferenceTimeUnit.Days TimeDifference=> DaysToKnownSat
SET WeeksToKnownSat TO DaysToKnownSat / 7
Variables.TruncateNumber.GetIntegerPart Number: WeeksToKnownSat Result=> RoundedWeeks
SET WeeksFromKnowSat TO RoundedWeeks + 1
DateTime.Add DateTime: KnownSat_Date TimeToAdd: WeeksFromKnowSat * 7 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> NextSat
Should look like this after you paste:
Best of luck!
eetuRobo
18
Super User 2025 Season 1
Nived_Nambiar
10
Super User 2025 Season 1
stampcoin
6