Is there any way to select the closest day of the week?

Stores DateTime for the current date value.

We need to get the day of the week for this date, and then select the closest day of the week (Tuesday, Thursday, or Friday) to get the date.

Example.)
If today is Sunday, then Tuesday (December 7 if today is December 5)
if today is Monday, then Tuesday (December 7 if today is December 6)
If today is Tuesday, then Thursday (December 7, then December 9)
If today is Wednesday, then Thursday (December 8, then December 9)
If today is Thursday, then Friday (December 9, then December 10)
If today is Friday, it will be Tuesday (if today is December 10, it will be December 14)
If today is Saturday, it will be Tuesday (if today is December 11, it will be December 14)

So, what is the best way in Uipath to get the nearest day of the week to today’s date?

Thank you in advance.

Can you please justify your condition more descriptively? Like if today is Thursday you have to select Friday?

Hi @Kirigirisu_Coin ,
Bit confusing one closest date in which criteria? your example are not clear.

you can make an switch case also because only 7 days will be there.
**

System.DateTime.Now.DayOfWeek.ToString()

**

Regards,
Arivu

Yes as @arivu96 Suggested Use switch cases as there will be only 7 cases
Ex for
For Monday
You can use DATE.Now.AddDays(1)

SIMILARLY For Remaining you can add days.

Condition will be : DateTime.Now.DayOfWeek.ToString

in general we can do it like following:
grafik
today.AddDays(+ {2,1,2,1,1,4,3}(today.DayOfWeek))

within the array we can configure the offset for each workday.
Kindly note:

  • first position is Sunday, index 1= Monday …
  • the rule for Tuesday is maybe Wendesday
  • instead of now we can use any datetime variable also
1 Like

There’s a way to do this.
I learned a lot.
Thank you very much.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.