cancel
Showing results for
Did you mean:
Anonymous
Not applicable

## DateDiff exclude weekend

Hello everyone,

I use the following formula to calculate the Days between two dates excluding the weekend:

```RoundDown(DateDiff(StartDate.SelectedDate, EndDate.SelectedDate, Days) / 7, 0) * 5 +
Mod(5 + Weekday(EndDate.SelectedDate) - Weekday(StartDate.SelectedDate), 5)```

But the problem is, that the formula doesnt calculate right. F.e.

StartDate=03.04.2022 and EndDate=09.04.2022

you get the result "2" but the rightone is "5".

Have someone an idea, what can be the problem? It must been use quit a lot as I seen in the forum, so it might be right.

Sincerly Vinc

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Found a way:

1+((DateDiff(
StartDate;
EndDate;
Days
))*5-((Weekday(StartDate)-Weekday(EndDate))*2))/7-Switch(
Weekday(EndDate);
7;
1;
0
)-Switch(
Weekday(StartDate);
1;
1;
0
)-CountIf(
Tabelle1;
Date >= StartDate;
Date <= EndDate
)

3 REPLIES 3
Most Valuable Professional

Hi @Anonymous ,

Congratulations - you have found a bug which seems to affect that 3 and 4 April but nothing else I can see. Try some other dates and you will see the formula is correct (which it is).

Anonymous
Not applicable

Puh, I wont use that form it produce to many mistakes.

Other example is, if ur Start.Date is 19.04.2022 and EndDate is 23.04.2022:

Result = 4 days but correct is 3

or 18.04.2022  to 23.04.2022 return "0".

Its not usable!

I try to built sth. else

Anonymous
Not applicable

Found a way:

1+((DateDiff(
StartDate;
EndDate;
Days
))*5-((Weekday(StartDate)-Weekday(EndDate))*2))/7-Switch(
Weekday(EndDate);
7;
1;
0
)-Switch(
Weekday(StartDate);
1;
1;
0
)-CountIf(
Tabelle1;
Date >= StartDate;
Date <= EndDate
)

Announcements

#### April 4th Copilot Studio Coffee Chat | Recording Now Available

Did you miss the Copilot Studio Coffee Chat on April 4th? This exciting and informative session with Dewain Robinson and Gary Pretty is now available to watch in our Community Galleries!   This AMA discussed how Copilot Studio is using the conversational AI-powered technology to aid and assist in the building of chatbots. Dewain is a Principal Program Manager with Copilot Studio. Gary is a Principal Program Manager with Copilot Studio and Conversational AI. Both of them had great insights to share with the community and answered some very interesting questions!     As part of our ongoing Coffee Chat AMA series, this engaging session gives the Community the unique opportunity to learn more about the latest Power Platform Copilot plans, where we’ll focus, and gain insight into upcoming features. We’re looking forward to hearing from the community at the next AMA, so hang on to your questions!   Watch the recording in the Gallery today: April 4th Copilot Studio Coffee Chat AMA