How to Find the Date Difference in C#
- 1). Define the first DateTime object. For example, you can store a value for midnight on August 20, 2000, with the line "System.DateTime timeOne = new System.DateTime(2000,8,20,0,0,0);" without quotes. The first parameter is the year, the second the month, the third the day, the fourth the hour, the fifth the minute and the sixth the second. Consult the MSDN DateTime documentation for more options.
- 2). Define the second DateTime object. For example, we can set it to July 20, 2010, with the line: "System.DateTime timeTwo = new System.DateTime(2010,7,20,0,0,0);".
- 3). Invoke the Subtract method within the DateTime object, storing the most recent value, and save the result in a new TimeSpan value. We can subtract from our previous sample with the command: "System.TimeSpan diffStore = timeTwo.Subtract(timeOne);".
- 4). Use the "Days" value within the TimeSpan inside your application. You can display it using: "Console.WriteLine(diffStore.Days);".
Source...