web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Apps
Answered

how to count dates

(0) ShareShare
ReportReport
Posted on by

i have 2 dropdowns for month & year .

Sequence(12) for month

Sequence(10,2022) for year.

 

here i want to count no .of working dates by selecting drop down, it should exclude weekends.

how to do this

Categories:
I have the same question (0)
  • Rajkumar_M Profile Picture
    3,747 Moderator on at

    Hi

    Try this

    Create two dropdowns for month and year, using the Sequence function to populate the items with the desired range of values.

    RoundDown(
    DateDiff( Date( Value(dropdownYear.Selected.Value),
    Value(dropdownMonth.Selected.Value), 1 ),
    Date( Value(dropdownYear2.Selected.Value),
    Value(dropdownMonth2.Selected.Value), 1 ), Days ) / 7, 0 ) * 5 +
    Mod( 5 + Weekday( Date( Value(dropdownYear2.Selected.Value),
    Value(dropdownMonth2.Selected.Value), 1 ) ) -
    Weekday( Date( Value(dropdownYear.Selected.Value),
    Value(dropdownMonth.Selected.Value), 1 ) ), 5
    )

    Thanks!

    If my response has been helpful in resolving your issue, I kindly request that you consider clicking "Accept as solution" and "giving it a thumbs up" as a token of appreciation.

  • JatinSaini Profile Picture
    428 on at

    Hi @venky232 ,

    Create a button control named "btnCountWorkingDates" with the Text property set to "Count Working Dates."

    Add the following code to the OnSelect property of the "btnCountWorkingDates" button:

     

    // Define the selected month and year
    Set(
     selectedMonth,
     Value(ddMonth.Selected.Value)
    );
    
    Set(
     selectedYear,
     Value(ddYear.Selected.Value)
    );
    
    // Calculate the number of working days
    Set(
     startDate,
     Date(selectedYear, selectedMonth, 1)
    );
    
    Set(
     endDate,
     Date(selectedYear, selectedMonth + 1, 0)
    );
    
    Set(
     workingDaysCount,
     0
    );
    
    ForAll(
     Filter(
     AddColumns(
     Sequence(endDate - startDate + 1, startDate),
     "DayOfWeek",
     Weekday(Date)
     ),
     DayOfWeek <> 1 && DayOfWeek <> 7 // Exclude Sunday (1) and Saturday (7)
     ),
     Set(
     workingDaysCount,
     workingDaysCount + 1
     )
    );
    
    // Show the result
    Notify("Number of working days: " & workingDaysCount, NotificationType.Success);
  • venky232 Profile Picture
    on at

    count showing wrong eg: in july month showing 24 days
    RoundDown(
    DateDiff(
    Date(
    Value(DRPYEAR.Selected.Value),
    Value(DRPMON.Selected.Value),
    1
    ),
    Date(
    Value(DRPYEAR.Selected.Value),
    Value(DRPMON.Selected.Value) + 1,
    1
    ),
    TimeUnit.Days
    ) / 7,
    0
    ) * 5 + Mod(
    11 - Weekday(
    Date(
    Value(DRPYEAR.Selected.Value),
    Value(DRPMON.Selected.Value),
    1
    )
    ),
    5
    )


  • venky232 Profile Picture
    on at

    with out button control not possible to show in label dynamically?

  • JatinSaini Profile Picture
    428 on at

    You could try copy pasting the overall code on the 'OnChange' property on both the dropdowns.

  • venky232 Profile Picture
    on at

    error at 

     Weekday(Date)

    Date is invalid

  • Rajkumar_M Profile Picture
    3,747 Moderator on at

    It works perfectly from my end.

    Rajkumar_404_0-1690384209541.png

     

  • venky232 Profile Picture
    on at

    iam using 1 dropdown for month & another dropdown for year, but in yout case u are using 4 dropdown

  • Verified answer
    Rajkumar_M Profile Picture
    3,747 Moderator on at

    @venky232 

    Instead of using a dropdown, you have the option to use a date picker to calculate the number of working days.

    RoundDown(DateDiff(datepicker1.SelectedDate, datepicker2.SelectedDate, Days) / 7, 0) * 5 +
    Mod(5 + Weekday(datepicker2.SelectedDate) - Weekday(datepicker1.SelectedDate), 5)

    Please refer to this link to calculate the number of working days if you are using the date picker: PowerApps Business Days Between Two Dates | Power Apps (devoworx.net)

    Excluding weekends and holidays in date differences in PowerApps | Microsoft Power Apps

    Thanks!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 914

#2
11manish Profile Picture

11manish 627

#3
Valantis Profile Picture

Valantis 598

Last 30 days Overall leaderboard