
Announcements
Hello,
I have a date, lets say : 18th March 2021.
Now, I require to get that date's week's Tuesday's date which should be 16th March 2021 - - How can I achieve that for any given date?
Thanks,
Hi @dave8 ,
Weekdays in PowerApps are from 1-7 starting on Sunday.
If your week starts on Sunday as Day 1, then Tuesdays would be Day 3.
You can then see if the selected date is before or after Tuesday and write a formula to get to the Tuesday for that week. It can get pretty confusing, but here's the logic;
If your selected date's day of the week is x and it's before a Tuesday, you want to subtract it from 3 to get the Delta between that day and Tuesday. You can then Add this delta back into your date as Days to get the Tuesday Date.
If your selected date's day of the week is x and it's after a Tuesday, you want to subtract 3 from it to get the Delta between that day and Tuesday. You can then subtract this delta from your date as Days to get the Tuesday Date.
Try this;
Add a DatePicker control.
Add a label and set its Text: property to;
If(Weekday(DatePicker1.SelectedDate)<=3,
Text(DateAdd(DatePicker1.SelectedDate, 3-Weekday(DatePicker1.SelectedDate), Days), LongDate),
Text(DateAdd(DatePicker1.SelectedDate, (Weekday(DatePicker1.SelectedDate) - 3)*-1, Days), LongDate))The Text function just displays the date nicely in the label, you can get rid of it just to get the date for other logic.
Hope this helps,
RT