cancel
Showing results for
Did you mean:
Frequent Visitor

## Set default date of date picker to first and last day of the week

Hello,

I have two Date Pickers (Start Date, End Date) in my powerapp which I use to filter the data. I have requirment to default the date picker values to start and end date of a week (Preferably , Monday-Sunday) .  Can anyone plesae help me to achevie this?

Thanks!

Apaco

1 ACCEPTED SOLUTION

Accepted Solutions
Power Apps

Hi,

Someone just asked me this today so I have a sample to share. 🙂 (see attached msapp file by going to create.powerapps.com, clicking open, and browsing to the msapp file)

The big idea is to find out the distance between Today, Monday and Sunday.

Find out what weekday today is relative to Monday. The 2 changes the point of reference so that the week begins on Monday. So Monday would be 1, Tuesday 2, Wed 3, ... Sunday 7.

`Weekday(Today(),2)`

Calculate the distance between today and Monday. If it's Monday (1), there's 0 difference because 1-1=0. If it's Friday (5), Monday would be -4 days away because 1-5=(-4).

`1-Weekday(Today(),2)`

Calculate when Monday would be by adding the difference calculated above to Today's date:

`DateAdd(Today(),1-Weekday(Today(),2),Days)`

Then you would repeat this for the end of the week. If you want Satuday, replace 1 with 6 in the formulas above. If you want Sunday, replace 1 with 7 in the formulas above.

Let me know how it goes for you.

4 REPLIES 4
Power Apps

Hi,

Someone just asked me this today so I have a sample to share. 🙂 (see attached msapp file by going to create.powerapps.com, clicking open, and browsing to the msapp file)

The big idea is to find out the distance between Today, Monday and Sunday.

Find out what weekday today is relative to Monday. The 2 changes the point of reference so that the week begins on Monday. So Monday would be 1, Tuesday 2, Wed 3, ... Sunday 7.

`Weekday(Today(),2)`

Calculate the distance between today and Monday. If it's Monday (1), there's 0 difference because 1-1=0. If it's Friday (5), Monday would be -4 days away because 1-5=(-4).

`1-Weekday(Today(),2)`

Calculate when Monday would be by adding the difference calculated above to Today's date:

`DateAdd(Today(),1-Weekday(Today(),2),Days)`

Then you would repeat this for the end of the week. If you want Satuday, replace 1 with 6 in the formulas above. If you want Sunday, replace 1 with 7 in the formulas above.

Let me know how it goes for you.

Frequent Visitor

Thank you !  It worked perfectly. 🙂

Frequent Visitor

this date syntax info is very helpful. thank you.

Helper III

I have the same problem. I want to set the default for a date picker to the start of the current week (Monday). I tried entering in

`DateAdd(Today(),1-Weekday(Today(),2),Days)`

to the DefaultDate option of the date picker, but is hasn't worked. I am getting an error message that 'Days' is not a recognized name.

Any thoughts on what is going on here?

Announcements

#### Microsoft Power Up program unveils new curriculum and more

New engaging and cohesive Power Up curriculum The Microsoft Power Up Program – a self-paced upskilling program, launched in 2022 to help non-technical professionals gain marketable skills using the Microsoft Power Platform – takes learning to the next level with a cohesive video-based curriculum that spans only seven weeks. Recognizing the demand for multimedia content, we partnered with Microsoft MVPs Rory Neary and Charlie Phipps to create engaging videos that not only simplify complex concepts, but also make the learner experience more dynamic and immersive. Each course follows the same business through real-world scenarios with demos and hands-on exercises for learners to gain skills and build solutions using Power Apps, Power Automate and Power BI. This structured approach not only enhances comprehension but also equips learners with tangible skills that can be applied immediately in their professional endeavors. By focusing on key areas, the program has been shortened from 12 weeks to seven, saving valuable time without sacrificing quality. Special thanks go to Microsoft Power Platform advocates, April Dunnam and Renee Noble who shared their expertise and to Power Up Program champs who contributed with feedback and reviews over the last 1+ year to make this significant improvement.   Easy access to a comprehensive Development Environment In addition, the program now offers simplified and instant access to a comprehensive development environment for Power Up Program learners to explore and experiment with the Power Platform in a sandbox environment, fostering creativity and innovation.     Introducing App-In-A-Day (AIAD) workshops for Power Up learners As an added incentive, participants of the Microsoft Power Up Program can now sign up for partner-led “App in a Day” virtual workshops. These workshops, conducted by industry experts and Microsoft partners, provide invaluable insights and practical guidance to supplement the core curriculum. By attending these workshops, learners can gain deeper insights into application development and further enhance their skills in leveraging the Power Platform for business solutions. A big shout to our partners that are supporting the Power Up Program and delivering these AIAD workshops: Advaiya, Almato AG, Braintree, Kaispe, Koenig Solutions, PowerApps 911, Pragmatic Works, Smart Consulting.   These enhancements introduced to the Microsoft Power Up Program mark a significant milestone in the ongoing quest to empower individuals with the skills needed to thrive in today’s digital economy. By embracing video-based learning, streamlining the curriculum, and offering personalized experiences, the program continues to set new standards of excellence in virtual education. Sign up today to start your Power Up learning journey (https://aka.ms/PowerUp/)   by Dimpi Gandhi, Principal PM Lead, Power Up ProgramRepost from Microsoft Power Platform Product Blog

#### Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Our team will be reviewing posts using the new "Copilot" label to ensure we highlight and amplify the most relevant and recent content, so you're assured of high-quality content every time you visit. If you share a post that gets featured in the curated gallery, you'll get a PM in the Community to let you know!The curated gallery is ready for you to experience now, so visit the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community. We can't wait to see what you "cook" up!