How to work with dates and times in c#?

The DateTime struct provides methods to work with dates and times.


  DateTime currentDateTime = DateTime.Now;
  Console.WriteLine("Current Date and Time: " + currentDateTime);


Using DateTime to perform date arithmetic and formatting:

  DateTime tomorrow = currentDateTime.AddDays(1);
  string formattedDate = currentDateTime.ToString("yyyy-MM-dd");
  Console.WriteLine("Tomorrow's Date: " + tomorrow);
  Console.WriteLine("Formatted Date: " + formattedDate);

Beginner's Guide to C#