Working with Dates and Times in C#
(Page 1 of 4 )
Every software engineer can testify that all kinds of projects, regardless of their purpose or how simple the requirements seem to be, deal with dates and mostly times. Fortunately, C# has built-in methods and properties that make our lives much easier. In this article we will present some of the most common techniques to manage and work with date and time variables.
Before we begin, you should be also informed that there are numerous other how-to articles covering various topics from the Windows registry up to regular expressions, lossless image conversion and resizing, working with collections, and more, published already here at ASP Free under the C# category. Be sure to check those out.
At the beginning of this article we will introduce the foundation concepts that must be understood in order to learn the rest. We will present the DateTime structure located in the System namespace. Moving on, its properties, methods, and constructors will also be explained thoroughly and also illustrated with examples (such as code samples with output).
This guide assumes familiarity with the C# syntax, but not with dates/times. It does not target professional coders, but rather those who are now learning how to code in C#. It's a great language to begin with; there's plenty of documentation along with proactive communities on various forums.
Thus, if you are ready to learn the basics of date and time handling in C# that are going to serve as a solid ground foundation to your further researches, let's begin! We are going to focus on explaining how to do the most necessary tasks such as assigning date and time, how to compare them with each other, various format conversions, and ultimately specific value extraction (such as part of a date).
Next: Brief Overview >>
More C# Articles
More By Barzan "Tony" Antal