web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Get date of next upcom...
Power Automate
Answered

Get date of next upcoming Saturday

(0) ShareShare
ReportReport
Posted on by

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!

I have the same question (0)
  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    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:

    MichaelAnnis_0-1697748702914.png


    Best of luck!



  • Murphys110 Profile Picture
    on at

    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!

  • Verified answer
    Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    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:

    Agnius_1-1697797953200.png

     

    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.

  • Murphys110 Profile Picture
    on at

    Many thanks! Will try that as well! 

  • Nived_Nambiar Profile Picture
    18,129 Super User 2025 Season 2 on at

    Hello @Murphys110 

     

    Sharing one more easy method for next date calculation using .Net Run script action see below

    Nived_Nambiar_0-1698252030615.png

     

    Inside of .Net run script action

    Nived_Nambiar_1-1698252055473.png

     

    Nived_Nambiar_2-1698252099304.png

     

    Code used 

    Nived_Nambiar_3-1698252116897.png

     

    output_date= CDate(input_date).AddDays(6-Cint(CDate(input_date).DayOfWeek)).ToString("dd\/MM\/yyyy")

     

    The output is 

    Nived_Nambiar_4-1698252148543.png

     

    which is next satuday's date.

     

    Hope this helps !

     

    Thanks & Regards,

    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! 🙌

  • Murphys110 Profile Picture
    on at

    Thank you!

  • Murphys110 Profile Picture
    on at

    Finally got a minute to try this... and it's INCREDIBLE! Love the simplicity of the solution... Thank you!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard