cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Resolver I
Resolver I

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 🙂 

 

Thanks,

Gavin

2 REPLIES 2
Highlighted
Community Support
Community Support

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.
Highlighted

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
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (6,679)