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 Platform Community / Forums / Power Apps / Calculate Week Between...
Power Apps
Answered

Calculate Week Between the Selected Date

(0) ShareShare
ReportReport
Posted on by 640

Hello All,

 

Is there any way we can calculate the total number of weeks between the selected date? 

 

Case: I have two Date pickers where users can select the start and end date. And I'm trying to display the total number of Weeks between the selected Dates. The week starts on Monday and ends on Sunday. 

 

i.e. Start Date 01/31/2022 End Date 05/08/2022 Total Weeks 14. 

Any Suggestions?

 

Thanks,

Omi

Categories:
I have the same question (0)
  • TheRobRush Profile Picture
    11,128 Moderator on at

    See code below, two date pickers are datepicker1 & datepicker2

     

    check before implementing what weekday() provides for Sunday and Saturday in your environment. In mine weeks run Sunday - Saturday and I believe that's default. So formula in my example uses that. If yours is different just change the 1 & 7 in formula to your sat&sun values

     

    If(
     Or(Weekday(DatePicker1.SelectedDate)=7,Weekday(DatePicker1.SelectedDate)=1),
     Sum(1,
     CountIf(
     ForAll(
     Sequence(
     DateDiff(
     DatePicker1.SelectedDate,
     DatePicker2.SelectedDate,
     Days
     )
     ),
     
     If(
     Or(
     Weekday(DateAdd(DatePicker1.SelectedDate,Value,Days))=1,
     Weekday(DateAdd(DatePicker1.SelectedDate,Value,Days))=7
     ),
     {Value:1})),Value=1)
     ),
     CountIf(
     ForAll(
     Sequence(
     DateDiff(
     DatePicker1.SelectedDate,
     DatePicker2.SelectedDate,
     Days
     )
     ),
     
     If(
     Or(
     Weekday(DateAdd(DatePicker1.SelectedDate,Value,Days))=1,
     Weekday(DateAdd(DatePicker1.SelectedDate,Value,Days))=7
     ),
     {Value:1})),Value=1)
    )
  • TheRobRush Profile Picture
    11,128 Moderator on at

    I misread this as weekend dates haha, one second the weeks I actually already have, and will post here

     

     

  • Verified answer
    TheRobRush Profile Picture
    11,128 Moderator on at

    Ok so here it is for calculating NUMBER of weeks contained in a range, it counts any portion of a week Sunday-Saturday. It also calculates properly if that date range stretches from 1 year into another.

     

    If(
     Year(DatePicker1)=Year(DatePicker2),
     Sum(
     WeekNum(DatePicker2.SelectedDate)-
     WeekNum(DatePicker1.SelectedDate))+
     1,
     Sum(
     WeekNum(DateValue(Concatenate(12,"/",31,"/",Year(DatePicker1))))-
     WeekNum(DatePicker1.SelectedDate)+
     WeekNum(DatePicker2.SelectedDate)+
     1
     )
    )
  • omi18 Profile Picture
    640 on at

    Hi @TheRobRush ,

     

    Thanks for the message. With the same formula, I'm getting 15. But I think it is supposed to be 14. 

     

    Screen Shot 2022-06-09 at 3.41.47 PM.png

     

    Thanks,

    Omi

  • TheRobRush Profile Picture
    11,128 Moderator on at

    If counting any portion of this date range it would be 15, because the final date, May 1st, falls on a sunday which is day 1 of a new week. 

  • TheRobRush Profile Picture
    11,128 Moderator on at

    Work Weeks in PowerApps by default run sun-saturday (theres a way to change the week start date in powerapps if you run say mond-sun instead)

  • timl Profile Picture
    37,160 Super User 2026 Season 1 on at

    That's a great solution @TheRobRush!

    The  Weekday/Weeknum functions accept a second argument to define the start of week. If you pass StartOfWeek.Monday, I guess that would cover the final piece of this? 

  • TheRobRush Profile Picture
    11,128 Moderator on at

    Great Timl, thank you for that. I never change mine so wasn't 100% sure of the modifier syntax

  • TheRobRush Profile Picture
    11,128 Moderator on at

    @omi18 that looks like 

     

     WeekNum(DatePicker2.SelectedDate,StartOfWeek.Monday)

     

  • omi18 Profile Picture
    640 on at

    No Problem, Thanks for the solution. 🍻

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 April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 610

#2
Haque Profile Picture

Haque 317

#3
WarrenBelz Profile Picture

WarrenBelz 315 Most Valuable Professional

Last 30 days Overall leaderboard