I want to subtract a number (that in a variable) from the current year

Hi Everyone
I have a current year - Now.Year (not in a variable)
and I have Experience (its string not double or int)
and I want to create a variable that will subtract the Experience from the current year.
Please help me

You can use
Now.adddays(-experience days in int)
or for years
Now.addyears(-experience year in int)

1 Like

@dlichtenstadt You can also try this :

Declare a String Variable say startYear, then use the below expression in an Assign Activity:

startYear = (Now.Year - Convert.ToDouble(Experience)).ToString

1 Like

Thank you very much
it worked
@ImPratham45 thank you also but it seemed to complicated!!

1 Like

I have another question
If I have a current date (15/06/2020 for example) and I want to subtract an amount of years that in a variable (str=20)
So the answer would be - 15/06/2000
how can i do that?

@dlichtenstadt Is the Current Date a String type ?

1 Like

Yes it can be
I just got a current date (Now.date) and it gave it to me in date type, and I change it to string!
but i got in the current date also the time - how can i delete that? and stay only with the date?

@dlichtenstadt So you just want to get the Date Part and not the Time? If So, you can try the following:

strDate = Now.ToString(“dd/MM/yyyy”)

1 Like

Hi @ dlichtenstadt

Please follow below steps to subtract 20 years, if you find it useful.

Assign string variable :- currentDate = now.Date.ToString(“dd-MM-yyyy”)

Assign string variable :- ExperienceStr = “20”

Double variable :- Experience = CDbl(ExperienceStr)

Assign String Variable:- SubtractYears = DateTime.ParseExact(currentDate,“dd-MM-yyyy”,System.Globalization.CultureInfo.InvariantCulture).AddYears(-CINT(Experience)).ToShortDateString

Input : 15-06-2020
Output : 06/15/2020

Thanks
Latika

1 Like

image

@ dlichtenstadt Please find the attached screenshot for Uipath code.

1 Like

thank you @Latika10011740 but it didn’t work

I did what u said and I have now only the date without the time
how do I subtract the EXP variable from the Date var (both in string)
input:
Date - 16/05/2020, EXP - “20”

output:
DateAfter - 16/05/2000

I did it and it didnt work (maybe my packages r not fully updated, but i cant update them…)

SubtractYears.xaml (5.7 KB)

Hi,@ dlichtenstadt

Please find the .Xmal attached for your reference.

Thanks
Latika

2 Likes

Hi,

Package version is not a problem.Please check the (Experience) variable Scope.

Thanks
Latika

1 Like

sorry
I just saw the answer and it was correct
sorry for the confuse…

1 Like

Yeah it worked!!!
sorry for that
But now I’m trying to remove the"/" and for some reason it change the order
instead “15062000” it gives me “06152000”
I tried subtract.replace("/","")

HI @

can you pls change the SubtractYears Variable value to :slight_smile:

DateTime.ParseExact(currentDate,“dd-MM-yyyy”,System.Globalization.CultureInfo.InvariantCulture).AddYears(-CINT(Experience)).ToString(“dd-MM-yyyy”)

Please find the attached updated Xaml.
SubtractYears_Updated.xaml (6.1 KB) Now you will get output as “15-06-2000”

1 Like

thank you for the quick answer
But I dont want “15-06-2000”
I want the answer like this “15062000”