cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate I
Advocate I

Obtain Dates from Weeknumber

Hi everyone!

Im having a doubt in PowerApps.

I was wondering if we can obtain the starting and ending dates from the weeknumber.

For example
So if the Week number is 10, the starting date should be 01-03-2020 and the ending date should be 07-03-2020. (Considering year as 2020 and the week starts with Sunday.)

Is there a way to find it?

Thank you for the help!!

Regards

(The original post for finding the week numbers - https://powerusers.microsoft.com/t5/Building-Power-Apps/Displaying-only-the-Weeks-of-the-current-mon...)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Obtain Dates from Weeknumber

Hi @DevadathanK ,

I'm so glad to meet your issue again.

Since I've answered your last post, let me  started from my previous reply.

Actually, you just need to make a little change from my previous reply.

The previous reply:

Filter(b,Value>=startweek,Value<=endweek)

//get current week num

Try this formula instead:

AddColumns(
       AddColumns(
            AddColumns(Filter(b,Value>=startweek,Value<=endweek),
                       "id",
                       Value-First(Filter(b,Value>=startweek,Value<=endweek)).Value
                       ),  //get the id value based on weeknum
            "startdate",
            DateAdd(Date(Year(Today()),Month(Today()),1),7*id,Days)
                   ),     //get the start date based on id
        "enddate",
        DateAdd(startdate,6,Days)      //get end date based on start date
           )

 Other steps are the same.

3122.PNG

 

 

Best regards,

Community Support Team _ Phoebe Liu
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

6 REPLIES 6
Highlighted
Community Champion
Community Champion

Re: Obtain Dates from Weeknumber

Hi @DevadathanK ,

I can start you on this and happy to help if you get stuck.

Firstly the formula (assuming DatePicker1 is your data source) for the current day of the year would be

DateDiff(
    Date(
        Year(DatePicker1.SelectedDate),
        1,
        1
    ),
    DatePicker1.SelectedDate
) + 1

The week number of the date would be

Round(
   ( 
      DateDiff(
         Date(
            Year(DatePicker1.SelectedDate),
            1,
            1
         ),
         DatePicker1.SelectedDate
      ) + 1
   )/7,0
)

You can get the day of the week with

Weekday(DatePicker1.SelectedDate)

So the start of the week date is

DatePicker1.SelectedDate - Weekday(DatePicker1.SelectedDate) +1

Please let me know how you go with this.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Highlighted
Advocate I
Advocate I

Re: Obtain Dates from Weeknumber

Hey @WarrenBelz,

Firstly, Thank you for trying to help me out 😃

So the input is not actually from a datepicker.

I already have the Week numbers with me. I need the start and end date corresponding to each weeknumber.
Highlighted
Community Champion
Community Champion

Re: Obtain Dates from Weeknumber

Thanks @DevadathanK ,

That is why I gave you all the formulas - I was not sure how you were doing it. I am not sure how you would reverse engineer the one from the date to the date number, but you could simply collect the 52 possibilities as below at App OnStart and do a Lookup.

ClearCollect(
    colWeekNos,
    {
        WeekNo: 1,
        WeekStart: DateValue("1/1/2020")
    },
    {
        WeekNo: 2,
        WeekStart: DateValue("1/8/2020")
    },
    {
        WeekNo: 3,
        WeekStart: DateValue("1/15/2020")
    },
    {
        WeekNo: 4,
        WeekStart: DateValue("1/22/2020")
    },
    {
        WeekNo: 5,
        WeekStart: DateValue("1/29/2020")
    }
)

Then 

Lookup(
   colWeekNos,
   WeekNo = Value(YourTextBox.Text),
   WeekStart
)

 

 Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Highlighted
Community Support
Community Support

Re: Obtain Dates from Weeknumber

Hi @DevadathanK ,

I'm so glad to meet your issue again.

Since I've answered your last post, let me  started from my previous reply.

Actually, you just need to make a little change from my previous reply.

The previous reply:

Filter(b,Value>=startweek,Value<=endweek)

//get current week num

Try this formula instead:

AddColumns(
       AddColumns(
            AddColumns(Filter(b,Value>=startweek,Value<=endweek),
                       "id",
                       Value-First(Filter(b,Value>=startweek,Value<=endweek)).Value
                       ),  //get the id value based on weeknum
            "startdate",
            DateAdd(Date(Year(Today()),Month(Today()),1),7*id,Days)
                   ),     //get the start date based on id
        "enddate",
        DateAdd(startdate,6,Days)      //get end date based on start date
           )

 Other steps are the same.

3122.PNG

 

 

Best regards,

Community Support Team _ Phoebe Liu
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

Highlighted
Community Champion
Community Champion

Re: Obtain Dates from Weeknumber

Hi @DevadathanK ,

The response from code guru @v-yutliu-msft is certainly more elegant than mine - tag me if if you want to continue with my logic.

Highlighted
Advocate I
Advocate I

Re: Obtain Dates from Weeknumber

Hi @v-yutliu-msft

As always your logic is amazing. Thank you so much for the advice.

I have made one small change to get the number of days for the first week of a month(because every month wont start with Sunday).

7-(Weekday(Date(Year(Today()),Month(Today()),1)

I added this to the first startdate to get the first enddate of the month and then from the 2nd set, added 6 days to get the end date as you suggested.

---------------------------------------------

Now let me tell you how i made modifications to my application according to your advice from the pervious post,

I was asked to make it so that the Sharepoint List that i used to make the App, could also be used to enter data when needed. So i had to make the 53 columns in the Sharepoint list.

You had showed me how to display the Weeks in a list box. I made it so that when a Week was selected from this list box, an input box for that particular week would be made visible just below the list box.

Since all 53 Datacards are already present in the app, eventho hidden, i used the earlier formula to find the duration of Week 1 and then from Week 2 to Week 53, i used

Set(startdate_1,DateAdd(enddate,1,Days))
Set(endate_1,DateAdd(startdate_1,6,Days))
And so on


Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,080)