I need to get current date and subtract 3 months.
It was doing conversions and subtracting 3 but going to go wrong at the turn of the year, in January for example it will result in month -2.
I think there is a better way to do this.
I need to get current date and subtract 3 months.
It was doing conversions and subtracting 3 but going to go wrong at the turn of the year, in January for example it will result in month -2.
I think there is a better way to do this.
Yes, there is a more appropriate way. The DateTime
structure has the method AddMonths
, to subtract a number of numbers is to use this method with a negative parameter.
For example
var data = new DateTime(2017, 01, 01);
var novaData = data.AddMonths(-3);