DateTime date = new DateTime(2021, 07, 15); DateTime futureDate = date.AddDays(7); Console.WriteLine(futureDate);
DateTime date = DateTime.Now; DateTime pastDate = date.AddDays(-30); Console.WriteLine(pastDate.ToShortDateString());Output: 18/05/2021 In this example, we use the AddDays method to subtract 30 days from the current date and store the result in a new DateTime object called pastDate. We then print the short date string representation of the pastDate object to the console. The package library for the DateTime class is part of the System namespace, which is included in the .NET Framework and .NET Core libraries.