How to get previous business day with one assign

Saturday and sunday holiday.

How to use one assign for getting value to string? I used this one but it doesnt work for saturdays

If(Now.AddDays(-1).DayOfWeek.ToString="Sunday",Now.AddDays(-3).ToString("dd.MM.yyyy"),Now.AddDays(-1).ToString("dd.MM.yyyy"))

@Betul_Dundar You may use below expression :

Assign DateString = If(Now.DayOfWeek = DayOfWeek.Saturday,Now.AddDays(-2).ToString(“dd.MM.yyyy”), If(Now.DayOfWeek = DayOfWeek.Sunday,Now.AddDays(-2).ToString(“dd.MM.yyyy”),Now.AddDays(-1).ToString(“dd.MM.yyyy”)))

Hi @Betul_Dundar

If(Now.AddDays(-1).DayOfWeek = DayOfWeek.Saturday, Now.AddDays(-3).ToString(“dd.MM.yyyy”), Now.AddDays(-1).ToString(“dd.MM.yyyy”))

Hi @Betul_Dundar

If(Now.DayOfWeek = DayOfWeek.Sunday, Now.AddDays(-3).ToString("dd.MM.yyyy"), Now.AddDays(-1).ToString("dd.MM.yyyy"))

Hope it helps!!

This code works incorrectly for Mondays. It needs to print Friday.

Change pravalli’s snippet froim DayOfWeek.Sunday to DayOfWeek.Monday

If today is Monday, substract 3 days, else substract 1 day.

Note that this is still an incomplete expression since you also need to correct input data Sunday -2 days. So you need to nest 2 if-then statements in each other if you really want to do it in 1 expression.

And even then you still need to compensate for national holidays.

My advice: don’t try and solve it in one expression but make it a wee bit more robust, and then export it as either a separate workflow of even library activity.

Hi @Betul_Dundar

Assign activity:
String currentDate

currentDate = If(Now.DayOfWeek = DayOfWeek.Saturday, Now.AddDays(-1).ToString("dd.MM.yyyy"), Now.ToString("dd.MM.yyyy"))

Hope it helps!!

Hello,
Please Refer below screenshot it might be Helpful.

str_PreviousBusinessDay=If(DateTime.Now.DayOfWeek=DayOfWeek.Monday,DateTime.Now.AddDays(-3),if(DateTime.Now.DayOfWeek=DayOfWeek.Sunday,DateTime.Now.AddDays(-2),if(DateTime.Now.DayOfWeek=DayOfWeek.Saturday,DateTime.Now.AddDays(-1),DateTime.Now.AddDays(-1)))).ToShortDateString

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