How to subtract a year from current datetime using c#?
The easiest way to subtract years from a date in Python is to use the dateutil extension. The relativedelta object from the dateutil. relativedelta module allows you to subtract any number of years from a date object.
Use DateTime. Subtract which will return TimeSpan , then use TotalSeconds property of the result which is of type double. Show activity on this post.
Just substract a month by 'adding` -1: var lastmonth = DateTime. Today. AddMonths(-1);
var myDate = DateTime.Now; var newDate = myDate.AddYears(-1);
DateTime oneYearAgoToday = DateTime.Now.AddYears(-1);
Subtracting a week:
DateTime weekago = DateTime.Now.AddDays(-7);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With