cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper III
Helper III

Add days to date and exclude weekends

Hello Guys,

I want to add a number of days to a date and place the result in another date field.

Default property of EndDateValue

StartDateValue + NoAnnual and exclude weekends


StartDateValue is a date field
EndDateValue is a date field

NoAnnual is a datacard format Number field



Please help!

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Hi @abieba ,

Could you please share a bit more about your scenario?

Do you want to add days to the start date with exclude weekends, then put the result into another date time filed?

 

I have made a test on my side, I think the Timer control could achieve your needs, please take a try with the following workaround:4.JPG

 

5.JPG

 

6.JPG

Add a Timer control within your app, set the Duration property to following:

1000

set the Repeat property and AutoStart property to following:

true

set the OnTimerEnd property of the Timer control to following:

Clear(BaseDateRange);
ForAll(
       FirstN([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20], Value(TextInput1.Text)),
       Collect(BaseDateRange, {RowIndex: CountRows(BaseDateRange) + 1, Date: DateAdd(StartDate.SelectedDate, Value)})
);
UpdateIf(BaseDateRange, Weekday(Date)=1||Weekday(Date)=7, {Date: Blank()});
Set(BlankDate, CountIf(BaseDateRange, IsBlank(Date)));
ForAll(
      RenameColumns(BaseDateRange, "RowIndex", "RowIndex1"),
      Patch(
                BaseDateRange,
                LookUp(BaseDateRange, RowIndex = RowIndex1),
                {
                    Date: DateAdd(StartDate.SelectedDate, RowIndex1 + BlankDate)
                }
            )
)

on your side, you may type:

Clear(BaseDateRange);
ForAll(
       FirstN([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20], Value(NoAnnualDataCardValue.Text)), /* <-- NoAnnualDataCardValue represents the Text Input box , where you enter the Days to add to the Start date */
       Collect(BaseDateRange, {RowIndex: CountRows(BaseDateRange) + 1, Date: DateAdd(StartDate.SelectedDate, Value)})
);
UpdateIf(BaseDateRange, Weekday(Date)=1||Weekday(Date)=7, {Date: Blank()});
Set(BlankDate, CountIf(BaseDateRange, IsBlank(Date)));
ForAll(
      RenameColumns(BaseDateRange, "RowIndex", "RowIndex1"),
      Patch(
                BaseDateRange,
                LookUp(BaseDateRange, RowIndex = RowIndex1),
                {
                    Date: DateAdd(StartDate.SelectedDate, RowIndex1 + BlankDate)
                }
            )
)

Set the Visible property of the Timer to following:

false     /* <-- Hide the Timer control in your app */

Set the DefaultDate property of the End Date Picker to following:

Last(BaseDateRange).Date

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Super User III
Super User III

@abieba 

You will want to consider using the DATEADD function for this.

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-dateadd-datediff

 

Example Usage

DateAdd(Now(), 3, Days)
DateAdd(DataCardValue.SelectedDate, 3, Days)

 

Perhaps you could put the result of this function in another DatePicker input and use the previous formula I supplied to make the calculation. https://powerusers.microsoft.com/t5/Building-PowerApps-Formerly/exclude-weekeneds-in-date-calculatio...

 

 

---
Please click "Accept as Solution" if my response helped to solve your issue so that others may find it more quickly. If your thought the post was helpful please give it a "Thumbs Up."

Hello @mdevaney 

i want to exclude weekends in the addition
so lets say i am adding 3 days to a thursday the result should show tuesday the following week instead of sunday.


Community Support
Community Support

Hi @abieba ,

Could you please share a bit more about your scenario?

Do you want to add days to the start date with exclude weekends, then put the result into another date time filed?

 

I have made a test on my side, I think the Timer control could achieve your needs, please take a try with the following workaround:4.JPG

 

5.JPG

 

6.JPG

Add a Timer control within your app, set the Duration property to following:

1000

set the Repeat property and AutoStart property to following:

true

set the OnTimerEnd property of the Timer control to following:

Clear(BaseDateRange);
ForAll(
       FirstN([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20], Value(TextInput1.Text)),
       Collect(BaseDateRange, {RowIndex: CountRows(BaseDateRange) + 1, Date: DateAdd(StartDate.SelectedDate, Value)})
);
UpdateIf(BaseDateRange, Weekday(Date)=1||Weekday(Date)=7, {Date: Blank()});
Set(BlankDate, CountIf(BaseDateRange, IsBlank(Date)));
ForAll(
      RenameColumns(BaseDateRange, "RowIndex", "RowIndex1"),
      Patch(
                BaseDateRange,
                LookUp(BaseDateRange, RowIndex = RowIndex1),
                {
                    Date: DateAdd(StartDate.SelectedDate, RowIndex1 + BlankDate)
                }
            )
)

on your side, you may type:

Clear(BaseDateRange);
ForAll(
       FirstN([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20], Value(NoAnnualDataCardValue.Text)), /* <-- NoAnnualDataCardValue represents the Text Input box , where you enter the Days to add to the Start date */
       Collect(BaseDateRange, {RowIndex: CountRows(BaseDateRange) + 1, Date: DateAdd(StartDate.SelectedDate, Value)})
);
UpdateIf(BaseDateRange, Weekday(Date)=1||Weekday(Date)=7, {Date: Blank()});
Set(BlankDate, CountIf(BaseDateRange, IsBlank(Date)));
ForAll(
      RenameColumns(BaseDateRange, "RowIndex", "RowIndex1"),
      Patch(
                BaseDateRange,
                LookUp(BaseDateRange, RowIndex = RowIndex1),
                {
                    Date: DateAdd(StartDate.SelectedDate, RowIndex1 + BlankDate)
                }
            )
)

Set the Visible property of the Timer to following:

false     /* <-- Hide the Timer control in your app */

Set the DefaultDate property of the End Date Picker to following:

Last(BaseDateRange).Date

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
secondImage

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

Top Kudoed Authors
Users online (25,763)