}
cancel
Showing results for
Did you mean:
Frequent Visitor

## How get the first / second / third / fourth date from the selected day?

Hi all,
I want to take a few dates from the selected day like this case:

1. If I choose 7/1/2020 to 10/31/2020, and choose The First Sunday of Every Month, then 7/5/2020,  8/2/2020, 9/6/2020, 10/4/2020 will be saved to new collection.
2. If I choose 7/1/2020 to 9/1/2020, and choose The Third Wednesday of Every Month, then 7/15/2020,  8/19/2020 will be saved to new collection.
3If I choose 7/1/2020 to 10/1/2020, and choose The Last Friday of Every Month, then 7/31/2020,  8/28/2020,  9/25/2020 will be saved to new collection.
How to get date on the selected day based on the case above? Any help is appreciated. Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support

Hi @AndiNoya ，

Do you want to list dates based on the 2 selected dates and selected which weekday?

Actually, this logic is very complex.

There's no directly function to get the dates based on selected which weekday. So the only solution is to list conditions one by one.

What's more, if there' no rule to select start date and end date, the logic will be more complex.

So I suggest you only select the first day of the month in the start date and end date, like 7/1/2020,10/1/2020,....

I only list some conditions blow, you could complete the rest based on my formulas:

1)datepicker3's OnChange:

``Set(startweek,Weekday(DatePicker3.SelectedDate))``

//start day weekday

2)datepicker4's OnChange:

``Set(endmonthweek,Weekday(Date(Month(DatePicker4.SelectedDate),1,1)));Set(endweek,Weekday(DatePicker4.SelectedDate))``

//end day weekday

3)drop down4's OnChange:

``Set(num,If(Dropdown4.Selected.Value="First",1,Dropdown4.Selected.Value="Second",2,Dropdown4.Selected.Value="Third",3,Dropdown4.Selected.Value="Fourth",4,Dropdown4.Selected.Value="Fifth",5))``

4)drop down5's OnChange:

``Set(week,If(Dropdown5.Selected.Value="Monday",2,Dropdown5.Selected.Value="Tuesday",3,Dropdown5.Selected.Value="Wednesday",4,Dropdown5.Selected.Value="Thursday",5,Dropdown5.Selected.Value="Friday",6,Dropdown5.Selected.Value="Saturday",7,Dropdown5.Selected.Value="Sunday",1))``

5)the label to list dates:

``````If(startweek<=week,
&","&
//date in first month
If(
Month(DatePicker3.SelectedDate)+1=Month(DatePicker4.SelectedDate),
""
)&","&
//if endmonth-startmonth=1,date in second month
If(Month(DatePicker3.SelectedDate)+1<Month(DatePicker4.SelectedDate),
//if endmonth-startmonth>=2,date in second month
If(Month(DatePicker3.SelectedDate)+2<Month(DatePicker4.SelectedDate),
//if endmonth-startmonth>=3,date in third month(choose 7/1/2020 to 10/1/2020)
....//please complete this part
If(Month(DatePicker3.SelectedDate)+10<Month(DatePicker4.SelectedDate),
//if endmonth-startmonth>=11,date in eleventh month (choose 1/1/2020 to 12/1/2020)
If(num=1&&Weekday(DatePicker4.SelectedDate)=week,DatePicker4.SelectedDate,"")
//the last month ``````

Then you could use Split function to split these dates. For example:

``ClearCollect(collection1,Split(Label1.Text,","))``

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.
2 REPLIES 2
Community Support

Hi @AndiNoya ，

Do you want to list dates based on the 2 selected dates and selected which weekday?

Actually, this logic is very complex.

There's no directly function to get the dates based on selected which weekday. So the only solution is to list conditions one by one.

What's more, if there' no rule to select start date and end date, the logic will be more complex.

So I suggest you only select the first day of the month in the start date and end date, like 7/1/2020,10/1/2020,....

I only list some conditions blow, you could complete the rest based on my formulas:

1)datepicker3's OnChange:

``Set(startweek,Weekday(DatePicker3.SelectedDate))``

//start day weekday

2)datepicker4's OnChange:

``Set(endmonthweek,Weekday(Date(Month(DatePicker4.SelectedDate),1,1)));Set(endweek,Weekday(DatePicker4.SelectedDate))``

//end day weekday

3)drop down4's OnChange:

``Set(num,If(Dropdown4.Selected.Value="First",1,Dropdown4.Selected.Value="Second",2,Dropdown4.Selected.Value="Third",3,Dropdown4.Selected.Value="Fourth",4,Dropdown4.Selected.Value="Fifth",5))``

4)drop down5's OnChange:

``Set(week,If(Dropdown5.Selected.Value="Monday",2,Dropdown5.Selected.Value="Tuesday",3,Dropdown5.Selected.Value="Wednesday",4,Dropdown5.Selected.Value="Thursday",5,Dropdown5.Selected.Value="Friday",6,Dropdown5.Selected.Value="Saturday",7,Dropdown5.Selected.Value="Sunday",1))``

5)the label to list dates:

``````If(startweek<=week,
&","&
//date in first month
If(
Month(DatePicker3.SelectedDate)+1=Month(DatePicker4.SelectedDate),
""
)&","&
//if endmonth-startmonth=1,date in second month
If(Month(DatePicker3.SelectedDate)+1<Month(DatePicker4.SelectedDate),
//if endmonth-startmonth>=2,date in second month
If(Month(DatePicker3.SelectedDate)+2<Month(DatePicker4.SelectedDate),
//if endmonth-startmonth>=3,date in third month(choose 7/1/2020 to 10/1/2020)
....//please complete this part
If(Month(DatePicker3.SelectedDate)+10<Month(DatePicker4.SelectedDate),
//if endmonth-startmonth>=11,date in eleventh month (choose 1/1/2020 to 12/1/2020)
If(num=1&&Weekday(DatePicker4.SelectedDate)=week,DatePicker4.SelectedDate,"")
//the last month ``````

Then you could use Split function to split these dates. For example:

``ClearCollect(collection1,Split(Label1.Text,","))``

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.
Frequent Visitor

Hi @v-yutliu-msft ,
I tried the formula you gave and it worked. but in 3rd case(The Last Friday of Every Month) it gave the wrong date

Announcements