Get Yesterday’s Date Using C#

Getting yesterday’s date using C# is easy.  All you have to do is to use the function .AddDays to add -1 day, so it returns the date of the previous day, which is yesterday.

More like this:

How to get yesterday’s date in C#

DateTime yesterday = DateTime.Today.AddDays(-1); // Today is 09/24/2021
Output
9/23/2021 12:00:00 AM

Happy coding!