Get Yesterday’s Date Using C#

Get 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!

Leave a Reply

Your email address will not be published. Required fields are marked *