In this example, I’ll show you How to get the difference between two dates in days using C#.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | class Program { static void Main(string[] args) { DateTime start = new DateTime(2019, 08, 16); DateTime end = new DateTime(2020, 09, 17); TimeSpan difference = end - start; //create TimeSpan object Console.WriteLine("Difference in days: " + difference.Days); //Extract days, write to Console. Console.ReadKey(); } } |
Output: