How do I get todays date one year ago in C#?
Asked
Active
Viewed 2.9k times
5 Answers
75
Todays date one year ago would be
DateTime lastYear = DateTime.Today.AddYears(-1);

Binary Worrier
- 50,774
- 20
- 136
- 184
-
4FYI, This takes into account leap year: If the current instance represents the leap day in a leap year, the return value depends on the target date: If value + DateTime.Year is also a leap year, the return value represents the leap day in that year. For example, if four years is added to February 29, 2012, the date returned is February 29, 2016. If value + DateTime.Year is not a leap year, the return value represents the day before the leap day in that year. For example, if one year is added to February 29, 2012, the date returned is February 28, 2013. – CD Waddell Apr 24 '14 at 13:48
6
What do you mean by "last years date"?
If you just want the date of today minus one year, try the following:
DateTime myDateTime = DateTime.Now.AddYears(-1);
I hope that is what you need.
UPDATE: Damn, I'm way to slow it seems :(

bbohac
- 333
- 2
- 12
3
DateTime.Now.AddYears(-1);

CD..
- 72,281
- 25
- 154
- 163
-
They were literally seconds later than the other guy not intentionally repeating answers... this is kinda crazy... – Zargold May 24 '17 at 19:42
3
using Fluent DateTime http://fluentdatetime.codeplex.com/
var oneYearAgo = 1.Years().Ago();

Simon
- 33,714
- 21
- 133
- 202
-
+1 At least this is different. Hopefully someone (@JonSkeet) will talk through the various ways of doing it in Noda Time! – Ruben Bartelink Nov 14 '12 at 20:48