As pointed by Dejan and Jonas Lomholdt,
`.Net 6` has the `DateOnly` type, it is a structure that is intended to represent only a date like a year, month, and day.
DateOnly d1 = new DateOnly(2022, 5, 16);
Console.WriteLine(d1); // 5/16/2022
Console.WriteLine(d1.Year); // 2021
Console.WriteLine(d1.Month); // 5
Console.WriteLine(d1.Day); // 16
Console.WriteLine(d1.DayOfWeek); // Monday
// Manipulation
DateOnly d2 = d1.AddMonths(3); // You can add days, months, or years. Use negative values to subtract. We are adding 3 months
Console.WriteLine(d2); // "8/16/2022" notice there is NO time
// You can use the DayNumber property to find out how many days are between two dates
int days = d2.DayNumber - d1.DayNumber;
Console.WriteLine($"There are {days} days between {d1} and {d2}"); //There are 92 days between 5/16/2022 and 8/16/2022
Full credit goes to Matt Johnson-Pint for this article:
[To see links please register here]