DateTime Struct
Explore how to create and manipulate dates and times using C#'s DateTime struct. Understand its constructors, retrieve current dates, identify days of the week, and add intervals like days or months. This lesson helps you manage precise date-time operations in your .NET applications.
We'll cover the following...
The DateTime struct is a value type that represents any date and time between midnight on January 1, 0001, and 11:59:59 PM on December 31, 9999.
Note: The DateTime struct follows the Gregorian calendar. We must account for this behavior if our application processes dates prior to October 15, 1582.
Creating a DateTime variable
Like other .NET types, we can initialize a DateTime value using one of its constructors:
Line 1: We create a
DateTimeinstance using the default constructor, which assigns the lowest possible value.Line 2: We print the default value to the console.
Line 4: ...