Getting error while calculating the date difference

Hello Team,

Getting error while calculating the date difference.
Can anyone please guide, what is the issue

Expression - DateDiff(DateInterval.Day, DateTime.ParseExact(date1, “dd.MM.yyyy”, System.Globalization.CultureInfo.InvariantCulture), DateTime.Now).Tostring

image

Hi @vaibhav2.chavan

Please give a try with

DateDiff(DateInterval.Day, DateTime.ParseExact(yourStringVar, "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture), DateTime.Now()).ToString()

Make sure the variable you are passing is type String

Regards!

To make it easier you can also use modify date activity:
image

@fernando_zuluaga - Still getting the same error

image

@iamNairda - Can you please give the example how to use this activity?

Hi @vaibhav2.chavan

How about this expression?

DateDiff(DateInterval.Day, DateTime.ParseExact(Date1, "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture), DateTime.Now).ToString()

Check out this thread and blog

Check out the Details of Modify Date activity

The Modify Date activity in UiPath is used to update a date value using modifications including adding or subtracting days and finding the first or last day of the week, month, or year

Here is an example of how to use the Modify Date activity to add 7 days to a date:

  1. Drag and drop the Modify Date activity onto your workflow.
  2. In the Properties panel, set the DateToModify property to the date you want to modify.
  3. Set the DaysToAdd property to 7.
  4. Set the Result property to a variable that will store the modified date.

You can also use the Add Days method of the DateTime object to add or subtract days from a date.

Check out the Docs

Regards
Gokul

1 Like