cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
gavinleung
Level 8

Find the dates between two dates excluding weekends

Hi folks, 

 

I noticed that the DateDiff calculation between two dates excluding weekends and holidays are well documented. I'm having an app that allow the users to pick a start date and end date for a task, and the task could be repetitive. So I'd like to find out the number of recurrences between the 2 dates excluding weekends, and most importantly to find out which exact dates they are. 

 

Here my code:

ClearCollect(collRecurrence,[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60]);
ClearCollect(_tempText,[]);
//DataCardValue9 is Start Date;
//DataCardValue10 is End Date;
//_NoOfSelected is the number of days where the task is repeating. Eg every 2 days, _NoOfSelected is 2;
Set(_Frequency, RoundDown((RoundDown(DateDiff(DataCardValue9.SelectedDate, DateValue(DataCardValue10.SelectedDate), Days) / 7, 0) * 5 + Mod(5 + Weekday(DateValue(_RepeatUntilSelected)) - Weekday(DataCardValue9.SelectedDate),5)) / _NoOfSelected, 0));
If(Toggle1.Value=true, 
ForAll(
    Filter(
        collRecurrence,
        Value < _Frequency
    ),
    Collect(_tempText, If(Weekday(DateAdd(DataCardValue9.SelectedDate, Value * _NoOfSelected)) = 1 Or Weekday(DateAdd(DataCardValue9.SelectedDate, Value * _NoOfSelected)) = 7, DateAdd(DataCardValue9.SelectedDate + 2, Value * _NoOfSelected), DateAdd(DataCardValue9.SelectedDate, Value * _NoOfSelected)));
    Reset(Toggle1);
),
Reset(Toggle1);
);

Obviously ... this code is not correct ... but I have no clue how to find out the exact dates. 

 

Please give me some advice Smiley Happy 

 

Thanks,

Gavin

2 REPLIES 2
Community Support Team
Community Support Team

Re: Find the dates between two dates excluding weekends

Hi @gavinleung ,

 

Did you mean that you want to find how many tasks start and end on the same day during one period of time? And also extract the dates between the start and end dates?

 

Regards,

Mona

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
gavinleung
Level 8

Re: Find the dates between two dates excluding weekends

Hi @v-monli-msft , not exactly. 

 

Say eg Task A will start on 20/9, and repeating every 2 days until 30/9. Weekends shouldn't be taken. That means Task A shall happen on 20/9, 24/9, 26/9 and 30/9. So the code I provided is to calculate the number of recurrence of this task, ie 4 times. But now, I don't know the code that I could extract these 4 dates and adding to a Sharepoint List.  

Helpful resources

Announcements
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 360 members 4,415 guests
Please welcome our newest community members: