tags:

views:

426

answers:

5

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
Exactly, thanks :)
JL
Jon B: Fixed, thanks :)
Binary Worrier
+1 for being so quick off the mark!
AdaTheDev
+3  A: 
DateTime.Now.AddYears(-1);
CD
+2  A: 
DateTime.Now.AddYears(-1)
AdaTheDev
+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
A: 

using Fluent DateTime http://fluentdatetime.codeplex.com/

var oneYearAgo = 1.Years().Ago();
Simon