Expand To Show Full Article
C# - Find number of days between two dates? | .NET Tutorials

How to calculate difference between two dates in C# ?

There are times when you might to calculate the difference between two days in C# and find the number of days between two dates in C#. This blog will explain how you can do that easily.

How to calculate difference between two dates in C# ?

Assuming both the start date and the end date are of type DateTime , we can use the TotalDays property to find the number of days between two days.

using System;

namespace DeveloperPublish
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime date1 = new DateTime(2015, 1, 18);
            DateTime date2 = new DateTime(2015, 1, 11);
            // Find the difference between two dates and get the Total Days
            double NoOfDays = (date1 - date2).TotalDays;
            Console.WriteLine(NoOfDays);
            Console.ReadLine();
        }
    }
}