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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Automate
Answered

Week ending dates

(1) ShareShare
ReportReport
Posted on by 7

I have created a recorded script that is working properly. The main issue I am having is that I have a couple of points in the run that a date needs to be input. That date is determined on whether the flow is being run on Monday or Tues - Friday. If it is on Monday, then it should use the previous Sunday date (04/22 would use 04/21), but the other 4 days of the week would use the next Sunday date (04/24 would use 04/28). I am new to Power Automate, so I am not sure how to get it to do this. 

 

Thank you for any help.

  • Verified answer
    trice602 Profile Picture
    16,679 Super User 2026 Season 2 on at

    Hi @lee_baldwin ,

     

    I think there are a ton of ways to do this and I will show you one that is functional and easy to understand.  So here I am getting the current date (run time) and then getting the "DOW" as Wednesday (example).

     

    Next I create a handful of cases, if = Monday, get current date - 1 to get the desired previous Sunday, else in each other case, I am adding days to the current date to get the next Sunday date, adding a different number of days for each DOW.

     

    In my example, since today is Wednesday, if gets next Sunday's date 4/28/2024.  Again, functional and easy to understand recognizing there are lots of ways to achieve the same result, others may even be more efficient.

     

    trice602_0-1713986417999.png

     

     

  • Verified answer
    Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hi @lee_baldwin 

     

    Another approach you can try is like below

     

    Nived_Nambiar_0-1714071030509.png

     

    Here i am using if else condition which checks whether date is monday or not, if monday , it takes previous day's date else it will run a .net script which calculates the next sunday for other days.

     

    refer the below code for more details

    DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateOnly CurrentDateTime=> CurrentDate
    Text.ConvertDateTimeToText.FromDateTime DateTime: CurrentDate StandardFormat: Text.WellKnownDateTimeFormat.ShortDate Result=> DateTextFormat
    Text.ConvertDateTimeToText.FromCustomDateTime DateTime: CurrentDate CustomFormat: $'''dddd''' Result=> Day
    IF Day = $'''Monday''' THEN
     DateTime.Add DateTime: CurrentDate TimeToAdd: -1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> ResultedDate
     Text.ConvertDateTimeToText.FromDateTime DateTime: ResultedDate StandardFormat: Text.WellKnownDateTimeFormat.ShortDate Result=> ResultedDate
    ELSE
     Scripting.RunDotNetScript Language: System.DotNetActionLanguageType.VisualBasic Script: $'''DayOfWeek= Cint(CDate(InputDate).DayOfWeek)
    NextSundayDate= CDate(InputDate).AddDays(7).AddDays(-DayOfWeek).ToString(\"dd-MM-yyyy\")''' @'name:InputDate': DateTextFormat @'type:InputDate': $'''String''' @'direction:InputDate': $'''In''' @'name:DayOfWeek': $'''''' @'type:DayOfWeek': $'''Int''' @'direction:DayOfWeek': $'''Out''' @'name:NextSundayDate': $'''''' @'type:NextSundayDate': $'''String''' @'direction:NextSundayDate': $'''Out''' @DayOfWeek=> DayOfWeek @NextSundayDate=> ResultedDate
    END
    

     

    Hope it helps !

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel
    Blog: Nived Nambiar's Blogs

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 426

#2
11manish Profile Picture

11manish 349 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 308

Last 30 days Overall leaderboard