How do I get last years date in C#
+15
A:
What do you mean by "Last years date".
Today, one year ago would be
DateTime lastYear = DateTime.Now.AddYears(-1);
is this what you're looking for?
Binary Worrier
2009-07-28 11:22:53
Exactly, thanks :)
JL
2009-07-28 11:23:16
Jon B: Fixed, thanks :)
Binary Worrier
2009-07-28 11:25:14
+1 for being so quick off the mark!
AdaTheDev
2009-07-28 11:27:30
+2
A:
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
2009-07-28 11:25:50
A:
using Fluent DateTime http://fluentdatetime.codeplex.com/
var oneYearAgo = 1.Years().Ago();
Simon
2009-09-04 12:36:32