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 / Get Dates of current w...
Power Apps
Answered

Get Dates of current week by weeknumber

(0) ShareShare
ReportReport
Posted on by 36

I've been looking for a way to get the current days of the current weeknumber so that when I press the left arrow by where it says "Week [WKNUM]" it'll decrement the weeknumber and recalculate the days of the new week. The same for if I press the arrow to the right of the week text, it'll increment the weeknumber and change the numbers. I am unable to figure it out after trying several formulas.

Clxmxnt25_0-1621827407116.png

I have values set in place like CurrentDay, CurrentWeek, CurrentWeekDay, CurrentMonth, CurrentYear and SelectedXXX counterparts that defaults to the CurrentXXX.

Categories:
I have the same question (0)
  • Verified answer
    v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @Clxmxnt25 ,

     

    I made a test for your reference:

    1\ OnVisible of the Screen:

    UpdateContext({CurrentWeek:RoundDown((10 + (DateDiff(Date(Year(Today()), 1, 1), Today(), Days)+1) - (Weekday(Today())-1)) / 7, 0) + 1});
    Clear(coldays);
    ForAll(Sequence(7,(7-Weekday(DateValue("2021.1.1")-1))+(CurrentWeek-1)*7-6,1) As D,Collect(coldays, DateAdd(DateValue("2021.1.1"), D.Value)))

     

    2\ Left icon:

    UpdateContext({CurrentWeek:CurrentWeek-1});
    Clear(coldays);
    ForAll(Sequence(7,(7-Weekday(DateValue("2021.1.1")-1))+(CurrentWeek-1)*7-6,1) As D,Collect(coldays, DateAdd(DateValue("2021.1.1"), D.Value)))

     

    3\ Right icon:

    UpdateContext({CurrentWeek:CurrentWeek+1});
    Clear(coldays);
    ForAll(Sequence(7,(7-Weekday(DateValue("2021.1.1")-1))+(CurrentWeek-1)*7-6,1) As D,Collect(coldays, DateAdd(DateValue("2021.1.1"), D.Value)))

     

    Result:

    3.gif

    The result collection "coldays" is the table for using. DateValue("2021.1.1") need to be modified to like

    DateValue(Concatenate(Text(CurrentYear),".1.1"))

     

    Hope this helps.

     

    Best regards,

    Community Support Team _ Jeffer Ni
    If this post helps, then please consider Accept it as the solution to help the other members find it.

  • Clxmxnt25 Profile Picture
    36 on at

    Thank you, that worked perfectly. Now for the issue of a new year or past year. If the current week is less than week1, I decrement the year and start at the total weeks of the previous year? And if it's greater than week52, I increment the year and reset Current week to 1. Correct?

    This is just to prevent it from showing week 0, -1 or week 53, 54 etc. I could hide that info but I need it to be visible

  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @Clxmxnt25 ,

     

    I think the approach could be forbid users from decreasing to 0 or more than 52, using an If function:

    Left icon:

    If(CurrentWeek = 1, Notify("...",NotificationType.Error), UpdateContext({CurrentWeek:CurrentWeek-1}))

    Right icon:

    If(CurrentWeek = 52, Notify("...",NotificationType.Error),UpdateContext({CurrentWeek:CurrentWeek+1}))

     

    Then for new years or past years, force CurrentWeek to be 1 to reset the weeks:

    If(CurrentYear != Year(Today()),UpdateContext({CurrentWeek: 1}))

     

    Best regards,

    Community Support Team _ Jeffer Ni
    If this post helps, then please consider Accept it as the solution to help the other members find it.

  • Clxmxnt25 Profile Picture
    36 on at

    I ended up doing this instead. This is for the right icon, the left icon is similar but with required changes.

    Set(
     totalWeeks,
     Round(
     (DateDiff(
     Date(
     SelectedYear,
     1,
     1
     ),
     Date(
     SelectedYear,
     12,
     31
     )
     ) + 1) / 7,
     0
     )
    );
    If(
     SelectedWeek >= totalWeeks,
     SelectedYear + 1;
     Set(SelectedWeek, 1),
     Set(SelectedWeek, SelectedWeek+1)
    );
    Set(SelectedMonth, Month(Date(SelectedYear, 1, 1)+SelectedWeek*7-1))
  • robinthakur Profile Picture
    32 on at

    This so very nearly works for my usecase which is similar but it calculates the dates wrong. This thinks Week 1 was 28/12/2020 - 03/01/2021 but in the UK at least, Week 1 was 04/01/2021-10/01/2021

  • Clxmxnt25 Profile Picture
    36 on at

    Could be a timezones thing, maybe? I'm also using Sunday as the start of week when calculating

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 356 Most Valuable Professional

#2
11manish Profile Picture

11manish 225 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 211

Last 30 days Overall leaderboard