cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DevadathanK
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
v-yutliu-msft
Community Support
Community Support

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
WarrenBelz
Super User III
Super User III

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.

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.

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.

v-yutliu-msft
Community Support
Community Support

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

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.

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
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

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

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

Top Solution Authors
Top Kudoed Authors
Users online (73,130)