How to subtract a number from a full date

Hi everyone
I have a date “Now.Tostring(“0101yyyy”)” and I want to subtract an Age variable from it.
for example,
Date= “01012020”
Age=“20” (it’s a string)
and I want that the date after the subtract will be like this
Date= “01012000”

You can try something like Now.addYears(cInt(“-”+age)).toString(“0101yyyy”)

1 Like

You can use: datetime.now.AddYears(-cint(Age)).ToString

1 Like

Thank u guys they both work!!!

For the rest of the people that will see this correspondence

In that one it gives also the time stamp so u need to add at the end - “tostring(“ddMMyyyy”)”, so the time stamp won’t show

1 Like

I have another Question
If I have the same Issue but now it’s with the months, I want to add two month (instead of May → July)
But I want to check each time before this change if the day is over 16
if it does - do the change
if Not - don’t do that change but add only one month ahead (May → June)
How can I do that?

Never mind I figured it out

  1. U need to get the current day (only day , like that: "DateTime.Now.Tostring(“dd”))
  2. than add an “If” activity
  3. The condition will be: “CInt(CurrentDate.ToString(“dd”))<16” (U need to convert the variable to Integer so u could check if it’s bigger or lower than the dayDate that u want in that case it’s “16”).