public static void Main()
{
System.DateTime _Now = DateAndTime.Now;
Console.WriteLine("The Date and Time is " + _Now);
//will return the date and time
Console.WriteLine("The Date Only is " + _Now.Date);
//will return only the date
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
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