cancel
Showing results for
Did you mean:
Level: Powered On

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

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

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.

2 REPLIES 2
Highlighted

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

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.

Level: Powered On

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

Thank you !  It worked perfectly.