Calculate the date based on today’s date

I need some help on calculating expiry date. Let’s says today date is 10-7-2019 and I need the robot to calculate 30days to find out what is the expiry date. Anyone have the code to share ? Thanks

Hi @Waka,

Use the below function:
String1: 10-7-2019



1 Like

Thanks, can we convert variable string ‘date’ to date time?

@Waka yes we can give like this Datetime.ParseExact(newdate.ToString,“dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture) it will give you the output as date format

I used the code above and I got an error message ‘String was not recognised as a valid date time’ to put it in datetime data type

I use it in Assign activity

@venkatmalla6 you can use Convert.ToDateTime(String). Cheers!!

@vikaskulhari you,re right buddy but if the date string is like this dd/mm/yyyy it is not works if the string date is mm/dd/yyyy

@venkatmalla6, this is happening because of your system date format. you can break your date and rearrange it in any format.

Hi Buddy @Waka

lets say we have a variable string with the date value like this
in_date = "10-7-2019"
then to get the 30 days from now
out_date = Convert.ToDatetime(in_date).AddDays(30).ToString(“dd-MM-yyyy”)

This worked buddy

Cheers @Waka

1 Like

It is working. Thanks.

Fantastic buddy
Cheers @Waka


My apology. After inserting the code. I got the same error message. Despite that I’ve changed all variables to string.

String was not recognised as a valid datetime

Before the assign, I’ve used get text activity to retrieve in_date.

1 Like

I found the solution in this threat as the problem come from UIpath

no worries
say if you have a variable with date value in string like this
in_date = "10-7-2019"
then the output would be
String out_date = Datetime.ParseExact(in_date,“MM-d-yyyy”,System.Globalization.CultureInfo.InvariantCulture).AddDays(30).ToString(“dd-MM-yyyy”)

what we need to concentrate is we need to mention the format of what in_date variable has, to the next format mentioned in Datetime.Parseexact
in_date = 10-7-2019 = MM-d-yyyy
so we mentioned as MM-d-yyyy next to it
if the format of in_date changes we need to mention the format next in the Parsing method accordingly
this worked as well

Cheers @Waka