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 / Date Difference betwee...
Power Apps
Answered

Date Difference between two date pickers but count end date as full day

(0) ShareShare
ReportReport
Posted on by 303

Hello everyone,

 

I need to calculate the difference between two dates, exclude weekends and holidays. The idea is that Start date is a full day and end date is also a full day. So if the start date was 2/24/2020 and the end date was 2/28/220 the total days would be 5. I tried adding a 1 to the formula I have for date difference but it interferes with when weekends are included in the date range. 

Formula I'm currently using: 

Value(((RoundDown(DateDiff(StartDate.SelectedDate, EndDate.SelectedDate, Days) / 7,0) * 5 + Mod(5 + Weekday(EndDate.SelectedDate) - Weekday(StartDate.SelectedDate), 5) -
CountIf(HolidaysCollection, StartD >= DataCardValue4.SelectedDate, StartD <= DataCardValue5.SelectedDate))+ 1) * 8)))

 

The CountIf() statement is referring to a company holiday collection. 

The +1 I added at the end of the formula is to count the end date as a full day.

The *8 is to convert the value into hours (work day).

 

Thanks!

Categories:
I have the same question (0)
  • PowerAddict Profile Picture
    7,316 Most Valuable Professional on at
    How about using DateDiff with units equal to minutes (or hours) and then dividing to figure out any partial days amd then convert the partial to a full day.

    Let me know if this helps.

    ---
    If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution.

    Thanks!
    Hardit Bhatia
    The Power Addict
    https://thepoweraddict.com
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @JMAFO 

    What have you tried? Can you post your formula?

  • JMAFO Profile Picture
    303 on at

    Certainly, I added the code in my original post above. 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @JMAFO 

    Your formula appears to be working for me so not sure what errors you are getting? I use Set() to set a variable to the formula output and display that in a label.

     

    My Set():

    Set(vNumDays02,Value(((RoundDown(DateDiff(StartDate.SelectedDate, EndDate.SelectedDate, Days) / 7,0) * 5 + Mod(5 + Weekday(EndDate.SelectedDate) - Weekday(StartDate.SelectedDate), 5) -
    CountIf(HolidayCol, HolDate >= StartDate.SelectedDate, HolDate <= EndDate.SelectedDate))+ 1) * 8))

    You do appear to have one too many )'s at the end of your formula but I just assumed that was from other things you maybe doing?

     

    Here it is in action:

    DateDiff_NoWendsHols.gif

    The first example above uses dates between 05/04/2020 - 05/15/2020 with 2 holidays inbetween and returns 8 days, as expected. The second, 05/08/2020 - 05/15/2020, 2 holidays, and returns 4 days.

     

    Maybe you just have a typo somewhere?

  • JMAFO Profile Picture
    303 on at

    Thank you for your response. This actually just helped me narrow it down to what's causing it; start date or end date being on a weekend. Is the output still correct for you when you do that?

  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @JMAFO 

    Ah yes, it is! I sorted a way to fix this though by using two variables.

     

    In the OnChange of DateStart datepicker add this code:

    Switch(Weekday(StartDate.SelectedDate),
     7, Set(vStart, DateAdd(StartDate.SelectedDate, 2,Days)),
     1, Set(vStart, DateAdd(StartDate.SelectedDate, 1,Days)),
     Set(vStart, StartDate.SelectedDate)
    )

    This formula sets the StartDate to the next Monday if a Saturday or Sunday is picked as the StartDate.

     

    Then, in the OnChange of the DateEnd datepicker add this code:

    Switch(Weekday(EndDate.SelectedDate),
     7, Set(vEnd, DateAdd(EndDate.SelectedDate, -1,Days)),
     1, Set(vEnd, DateAdd(EndDate.SelectedDate, -2,Days)),
     Set(vEnd, EndDate.SelectedDate)
    )

    This formula sets the EndDate to a Friday if a Saturday or Sunday is picked as the EndDate.

     

    Then to finish, change all of the references to StartDate.SelectedDate to vStart and EndDate.SelectedDate to vEnd. This seems to be working at my end but maybe just run a few checks yourself.

     

     

  • JMAFO Profile Picture
    303 on at

    Works like a charm. Genius and complete solution to my problem. 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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 385

#2
Vish WR Profile Picture

Vish WR 367

#3
timl Profile Picture

timl 340 Super User 2026 Season 1

Last 30 days Overall leaderboard