LDPens
1
Hello.
I have a problem when I try to subtract a day from a DateTime variable.
I have a variable, let’s call it “Original_Date” which is equal to “01/07/2021” and has the dd/MM/yyyy format.
I then want to subtract a day from the variable Original_Date, by using: Original_date.addDays(-1).toString(“dd/MM/yyy”)
and save it as the variable “New_Date”
The dateTime variable New_Date should then be “30/07/2021”. Now it returns “01/06/2021”, which is wrong.
It subtracts a number of the month, and not the days as it should.
Can someone help me out? Thanks!
Gokul001
(Gokul Balaji)
2
Hi @LDPens
You can try with this expression
-
Use Assign Activity (Subtract Days)
DateTime.ParseExact(“01/07/2021”(“dd/MM/yyyy”),Globalization.CultureInfo.InvariantCulture).AddDays(-1).ToString(“dd/MM/yyyy”)
-
Use Assign Activity (Subtract Month)
DateTime.ParseExact(“01/07/2021”(“dd/MM/yyyy”),Globalization.CultureInfo.InvariantCulture).AddDays(-1).ToString(“dd/MM/yyyy”)
Regards
Gokul
1 Like
Hi @LDPens,
There should be .AddMonths available on your datetime, similar to .AddDays
This is from a colleague’s code, neg
is the amount of months you need to remove and is dynamic.
1 Like
LDPens
4
Perfect! Thank you @Gokul001
Gokul001
(Gokul Balaji)
5
Hi @LDPens
That’s Great
If it is work then mark as solved.
Regards
Gokul
system
(system)
Closed
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.