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

Exclude the weekends

Hi 

 

How do I the exclude the weekends from the formula below?

MiteshGovan_0-1619197280109.png

Text(DateAdd(DatePicker2.SelectedDate, Value(Date_Estimator_LBL.Text), Days),DateTimeFormat.LongDate)

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions

You can use the Text function at the date result of the With function:

With(
    { weekDaysToAdd: Value(Date_Estimator_LBL.Text) },
    With(
        {
            fullWeeks: RoundDown(weekDaysToAdd / 5, 0),
            remainingDays: Mod(weekDaysToAdd, 5),
            daysToWeekend: 5 - Weekday(DatePicker1.SelectedDate, StartOfWeek.Monday)
        },
        With(
            { daysToAdd: fullWeeks * 7 + remainingDays + If(remainingDays > daysToWeekend, 2, 0) },
            Text(DateAdd(DatePicker1.SelectedDate, daysToAdd), DateTimeFormat.LongDate))))

or

With(
    { dateAfterAdd: DateAdd(DatePicker1.SelectedDate, Value(Date_Estimator_LBL.Text)) },
    With(
        { weekday: Weekday(dateAfterAdd, StartOfWeek.Sunday) },
        Text(
            DateAdd(dateAfterAdd, If(weekday = 1 /* Sunday */, 1, weekday = 7 /* Saturday */, 2, 0)),
            DateTimeFormat.LongDate)))

View solution in original post

4 REPLIES 4
CarlosFigueira
Power Apps
Power Apps

Are you looking to exclude weekends from the days added to the selected date, or choose the first weekday after adding the days to the selected date? For example, if SelectedDate is 2021-04-09 (Friday) and Value(Date_Estimator_LBL.Text) is 8, do you want the result to be 2021-04-21 (Wednesday, 8 non-weekend days after 2021-04-09) or 2021-04-19 (Monday, first weekday after selecteddate+value)? Or something else?

If you want to exclude weekends from the days added to the date, you can use an expression like this (it currently doesn't work if the selected date on the date picker is on a weekend, but can be adjusted if this is a problem):

With(
    { weekDaysToAdd: Value(Date_Estimator_LBL.Text) },
    With(
        {
            fullWeeks: RoundDown(weekDaysToAdd / 5, 0),
            remainingDays: Mod(weekDaysToAdd, 5),
            daysToWeekend: 5 - Weekday(DatePicker1.SelectedDate, StartOfWeek.Monday)
        },
        With(
            { daysToAdd: fullWeeks * 7 + remainingDays + If(remainingDays > daysToWeekend, 2, 0) },
            DateAdd(DatePicker1.SelectedDate, daysToAdd))))

Or if you want to get the first weekday after adding the days:

With(
    { dateAfterAdd: DateAdd(DatePicker1.SelectedDate, Value(Date_Estimator_LBL.Text)) },
    With(
        { weekday: Weekday(dateAfterAdd, StartOfWeek.Sunday) },
        DateAdd(dateAfterAdd, If(weekday = 1 /* Sunday */, 1, weekday = 7 /* Saturday */, 2, 0))))

Hope this helps!

Hi

 

Thank you. How do I add Long Date to both of the formula's.

 

Kind Regards,

You can use the Text function at the date result of the With function:

With(
    { weekDaysToAdd: Value(Date_Estimator_LBL.Text) },
    With(
        {
            fullWeeks: RoundDown(weekDaysToAdd / 5, 0),
            remainingDays: Mod(weekDaysToAdd, 5),
            daysToWeekend: 5 - Weekday(DatePicker1.SelectedDate, StartOfWeek.Monday)
        },
        With(
            { daysToAdd: fullWeeks * 7 + remainingDays + If(remainingDays > daysToWeekend, 2, 0) },
            Text(DateAdd(DatePicker1.SelectedDate, daysToAdd), DateTimeFormat.LongDate))))

or

With(
    { dateAfterAdd: DateAdd(DatePicker1.SelectedDate, Value(Date_Estimator_LBL.Text)) },
    With(
        { weekday: Weekday(dateAfterAdd, StartOfWeek.Sunday) },
        Text(
            DateAdd(dateAfterAdd, If(weekday = 1 /* Sunday */, 1, weekday = 7 /* Saturday */, 2, 0)),
            DateTimeFormat.LongDate)))

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (17,320)