Introduction
If you're building a Time Sheet App in PowerApps and must display the working weekday start and end dates based on a week's selection, this article will help you.
Follow the below steps to display the start date and end date
Step 1. Add dropdown for week selection
Add a dropdown, select its Items property, and add the formula below to display numbers from 0 up to 53.
Sequence(54,0)
Step 2. Set start date for Monday
To add a date picker control for the working week start date and show the Monday's date of the selected week, first select the DefaultDate property of the date picker control and add the code below.
If(
drpWeekNo.Selected.Value = 0,
Blank(),
With(
{
year: Year(Today()),// Get the current year
weekNo: drpWeekNo.Selected.Value //Get the select week number
},
Date(year,1,1) + ((weekNo - 1) * 7 - Weekday(Date(year,1,1)) + 2) //Get Week Start Date
)
)
Step 3. Set the end date for Friday
To add a date picker control for the working week start date and show the Friday’s date of the selected week, first select the DefaultDate property of the date picker control and add the code below.
If(
drpWeekNo.Selected.Value = 0,
Blank(),
With(
{
year: Year(Today()), // Get the current year
weekNo: drpWeekNo.Selected.Value //Get the select week number
},
Date(year, 1, 1) + ((weekNo - 1) * 7 - Weekday(Date(year, 1, 1)) + 2 + 4) //Get Week End Date
)
)
Conclusion
With this article, you can easily calculate the working week's start date (Monday date) and end date (Friday date) based on the selected week.