Indentify the previous business day

studio

#1

Hi,

Now I’m working on the RPA development and I would like to how to identify the previous business day in US.
We need to identify the folder of previous business day and how can I achieve this?

Best Regards,
Takuya


#2

Hi @11115,

Refer the below code to get the last business day.

` var holidays = new List<DateTime>{/* list of observed holidays */};
DateTime lastBusinessDay = new DateTime();
var i = DateTime.DaysInMonth(year, month);
while (i > 0)
{
  var dtCurrent = new DateTime(year, month, i);
  if(dtCurrent.DayOfWeek < DayOfWeek.Saturday && dtCurrent.DayOfWeek > DayOfWeek.Sunday && 
   !holidays.Contains(dtCurrent))
    {
      lastBusinessDay = dtCurrent;
      i = 0;
    }
    else
    {
      i = i - 1;
    }
}`

Directory.Exists(path) use this code to get the lost of folders from the path after that using filter get the folder based on your date.

Regards,
Arivu


#3

Hi @11115
Made few changes based on @arivu96 's edition. Main.xaml (15.9 KB)


#4

Hi Arivu and Windell,

Thank you for your support.
It looks great but it does not support the date of beginning of the month.
How can we handle it?

Best Regards,
Takuya


#5

Hi 11115
Here I did few changes, now it should work.Main.xaml (13.5 KB)
Notice it works only for one previous workday , still can’t handle any given days (Your chances to Update). To make it works for the whole year, a full list of holidays required to add manually


How to get the holidays with VB in uipath?
#6

Hi Windell,

Thank you so much for your support.
Now it works well.

Best Regards,
Takuya


#7

Hi Windell,
Holidays are working in the xaml file , I have included 2018518 in your code to exempt 18/05/2018 but its still showing the 10/05/2018 for the last day