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 Platform Community / Forums / Power Apps / How to exclude just Su...
Power Apps
Answered

How to exclude just Sunday from date difference

(0) ShareShare
ReportReport
Posted on by 212

I'm working on tweaking this formula:
Solved: Excluding weekends using DateDiff and Datepicker - Power Platform Community (microsoft.com)

So it excludes Sundays from two dates. I'm currently using this:

Set(varAdd14Days, DateAdd(selectedDate, 14, TimeUnit.Days));

Set(varCalculateAmtOfDays, RoundDown(DateDiff(selectedDate, varAdd14Days, TimeUnit.Days) / 7, 0) * 5 +
 Mod(5 + Weekday(varAdd14Days) - Weekday(selectedDate), 5));

Set(varActualReturnDate, DateAdd(selectedDate, varCalculateAmtOfDays, TimeUnit.Days)); 

It's for a loan service. A user will book an item, they get it for 14 days, then have to return it. At the moment this formula is (apparently) excluding weekends, whereas I only want it to exclude Sundays.
The final line of the above, will show the return date to the user.
Need to exclude Sundays. 

Categories:
I have the same question (0)
  • Verified answer
    mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at

    hey @cardinalnight 

     

    can you try this approach please:

     

    Set(varAdd14Days, DateAdd(selectedDate, 14, TimeUnit.Days));
    
    // Calculate the total number of days initially
    Set(varTotalDays, DateDiff(selectedDate, varAdd14Days, TimeUnit.Days) + 1);
    
    // Calculate the number of Sundays
    Set(varFirstSunday, If(Weekday(selectedDate) > 1, 8 - Weekday(selectedDate, StartOfWeek.Monday), 1));
    Set(varDaysTillFirstSunday, varFirstSunday - 1);
    Set(varEffectiveDays, varTotalDays - varDaysTillFirstSunday);
    Set(varNumberOfSundays, If(varEffectiveDays >= 0, RoundDown(varEffectiveDays / 7, 0) + 1, 0));
    
    // Calculate the actual return date excluding Sundays
    Set(varActualReturnDate, DateAdd(selectedDate, varTotalDays + varNumberOfSundays - 1, TimeUnit.Days)); 
    

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • cardinalnight Profile Picture
    212 on at

    Thank you. I've added to this system of weekday checks with this:

    Set(varAdd14Days, DateAdd(selectedDate, 14, TimeUnit.Days));
    
    // Calculate the total number of days initially
    Set(varTotalDays, DateDiff(selectedDate, varAdd14Days, TimeUnit.Days) + 1);
    
    // Calculate the number of Sundays
    Set(varFirstSunday, If(Weekday(selectedDate) > 1, 8 - Weekday(selectedDate, StartOfWeek.Monday), 1));
    Set(varDaysTillFirstSunday, varFirstSunday - 1);
    Set(varEffectiveDays, varTotalDays - varDaysTillFirstSunday);
    Set(varNumberOfSundays, If(varEffectiveDays >= 0, RoundDown(varEffectiveDays / 7, 0) + 1, 0));
    
    // Calculate the actual return date excluding Sundays
    Set(varActualReturnDate, DateAdd(selectedDate, varTotalDays + varNumberOfSundays - 1, TimeUnit.Days)); 
    // If the return day is a Sunday, push it to Monday if not, then use varActualReturnDate:
    If(Weekday(varActualReturnDate) = 1, Set(varIfSunday, DateAdd(varActualReturnDate, 
    1,TimeUnit.Days)), Set(varIfSunday, varActualReturnDate));

    Hopefully there shouldn't be any issues with my addition of the final line there. I've tested it and it works.

    Hopefully this helps someone with the same challenge.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 914

#2
11manish Profile Picture

11manish 617

#3
Valantis Profile Picture

Valantis 598

Last 30 days Overall leaderboard