Back to course

Working with Dates and Times

C# Zero to Hero: Comprehensive Programming Masterclass

DateTime and TimeSpan

C# provides the DateTime struct to work with dates.

Common Tasks

  • DateTime.Now: Current date and time.
  • DateTime.AddDays(5): Adding time.
  • date.ToString("yyyy-MM-dd"): Formatting.

TimeSpan

Used to represent a duration of time (e.g., the difference between two dates).