how to get yesterday's date in C#

The Solution to how to get yesterday's date in C# is


Use DateTime.AddDays() method with value of -1

var yesterday = DateTime.Today.AddDays(-1);

That will give you : {6/28/2012 12:00:00 AM}

You can also use

DateTime.Now.AddDays(-1)

That will give you previous date with the current time e.g. {6/28/2012 10:30:32 AM}

~ Answered on 2012-06-29 05:26:34


Most Viewed Questions: