This article will teach you how to get yesterday’s date using C#. Many developers want to get yesterday’s date for too many reasons. It’s an easy and simple solution using the AddDays
function. Passing (-1) to the AddDays
function will return today’s date minus one day, which is yesterday’s date!
As mentioned before, use the AddDays
function to get yesterday’s date:
DateTime yesterdayDate = DateTime.Today.AddDays(-1); // Today is 06/09/2022 Console.WriteLine(yesterdayDate );
Output
06/09/2022
Happy Coding!