How to add 8 business working days in uipath i want to exclude sat and sunday

how to add 8 business working days in UiPath
i want to exclude sat and sunday

ex if date is on friday 3 feb …here i want the date as 13 feb as i have to exclude sat and Sunday

simlarly if date is on monday 5th feb …out put should be 14 th feb

basically i want to exclude the non working days

@T_Y_Raju

i have no idea on this

any other method to do this.

@T_Y_Raju

yourDateVariable.AddDays(If(yourDateVariable.DayOfWeek = DayOfWeek.Friday, 10, 8 + If(yourDateVariable.DayOfWeek = DayOfWeek.Saturday, 2, If(yourDateVariable.DayOfWeek = DayOfWeek.Sunday, 1, 0))))

Hey @T_Y_Raju
you can use this vb,net code:

Dim businessDaysToAdd As Integer = 8
Dim addedDays As Integer = 0

While addedDays < businessDaysToAdd
    initialDate = initialDate.AddDays(1)

    If initialDate.DayOfWeek <> DayOfWeek.Saturday AndAlso initialDate.DayOfWeek <> DayOfWeek.Sunday Then
        addedDays += 1
    End If
End While

resultDate = initialDate
  • Input Arguments - initialDate (DateTime) - The starting date.
  • Output Arguments - resultDate`(DateTime) - The resulting date after adding 8 business days.

Hi @T_Y_Raju

Try this:

DateTime.ParseExact("5 Feb", "d MMM", System.Globalization.CultureInfo.InvariantCulture).AddDays(If(DateTime.ParseExact("5 Feb", "d MMM", System.Globalization.CultureInfo.InvariantCulture).DayOfWeek = DayOfWeek.Friday, 10, 8)).AddDays((Math.Floor((DateTime.ParseExact("5 Feb", "d MMM", System.Globalization.CultureInfo.InvariantCulture).DayOfWeek + 2) / 7) * 2) + 1)

Hope it helps!!

One of many options:

Enumerable.Range(1,15).Select(Function (x) myDate.AddDays(x)).Where(Function (x) Not {0,6}.Contains(x.DayOfWeek))(6)

if needed Convert / parse a string into a DateTime - myDate

EDITED / ADDED
When an Addition of 8 BusinessDays is to calculate like this:
grafik

we just modify the access index

will this work for any month or only for specfic dates?

Hi @T_Y_Raju

DateTime.ParseExact("5 Feb", "d MMM", System.Globalization.CultureInfo.InvariantCulture).AddDays(If(DateTime.ParseExact("5 Feb", "d MMM", System.Globalization.CultureInfo.InvariantCulture).DayOfWeek = DayOfWeek.Friday, 10, 8)).AddDays((Math.Floor((DateTime.ParseExact("5 Feb", "d MMM", System.Globalization.CultureInfo.InvariantCulture).DayOfWeek + 2) / 7) * 2) + 1)

Instead of 5 Feb you can change the dates as required.

Regards

when iam putting my choice date it is giving the following error

i have taken date as string

Hi @T_Y_Raju

Try this:

DateTime.ParseExact("02/05/2024", "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture).AddDays(If(DateTime.ParseExact("02/05/2024", "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture).DayOfWeek = DayOfWeek.Friday, 10, 8)).AddDays((Math.Floor((DateTime.ParseExact("02/05/2024", "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture).DayOfWeek + 2) / 7) * 2) + 1)

Change the format from d MMM to MM/dd/yyyy. This should solve the error.

Regards

Hi @T_Y_Raju,

I know that there are many ways to do this by performing logic and arithmetic calculations. But, are you considering holidays? I worked on a project with a similar requirement and I used the BusinessDaysCalculator activity:

image

Just install it, select the country of preference, and calculate the days as needed. No complex calculations.

This is the code that I created to add 10 business days to a DateTime variable.


image

Juan P.

if i take date of 1 macrh 2024 then 8 working days would be 12 march

but it is giving wrong result as 14 march

To add 8 business working days to a date while excluding weekends in UiPath, you can use the following approach:

  1. Assign Activity*: Create a variable to hold the initial date.
  2. While Loop*: Use a While loop to iterate through each day, adding a day at a time.
  3. If Activity*: Inside the loop, use an If activity to check if the current day is not Saturday or Sunday.
  4. Add Business Days*: If it’s a business day, increment a counter.
  5. Break Condition*: Exit the loop when the counter reaches 8.

Here’s a workflow code for the above steps:

startDate = new DateTime(2023, 2, 3) // Replace with your start date
businessDaysToAdd = 8
addedDays = 0

While addedDays < businessDaysToAdd
startDate = startDate.AddDays(1)
If startDate.DayOfWeek <> DayOfWeek.Saturday AndAlso startDate.DayOfWeek <> DayOfWeek.Sunday Then
addedDays += 1
End If
End While

// Output startDate will have the date after adding 8 business days

whre do i have to write this expression in assign
please suggest

we just use an Assign Activity

myDate2 | DataType: DateTime =

Enumerable.Range(1,15).Select(Function (x) myDate.AddDays(x)).Where(Function (x) Not {0,6}.Contains(x.DayOfWeek))(6)

myDate Variable is as described above a DateTime DataType

And if you need myDate2 as a formatted string just do:

Assign Activity:
strEndDate = myDate2.ToString(…) … = your needed format string

how can we remove 0000 at the end of the date

image

please share with us a screenshot illustrating your question

DateTime Variables we do not touch the internal structure
grafik

with toString we can configure a formated string output:
grafik

as also mentioned above