Compare two DATE and get Days in c#
<p>Count Number of days by comapaing two date, When you want to compare two date like due Date and return date of a book in library then you can get no of days in this manner</p>

<pre><code>        int TotalDay;
        DateTime due = OldDate;

        int day = due.Day;
        int nday = DateTime.Now.Day;
        int mnt = due.Month;
        int nmnt = DateTime.Now.Month;
        int yr = due.Year;
        int nyr = DateTime.Now.Year;
        if (nyr &lt;= yr)
        {
            if (nmnt &lt;= mnt)
            {
                if (nday &gt; day)
                {
                    TotalDay = nday - day;
                }
            }
            else
            {
                TotalDay = nday - day;
                m = nmnt - mnt;
                TotalDay = d + (m * 30);
            }
        }
        else
        {
            TotalDay = nday - day;
            m = nmnt - mnt;
            TotalDay  = d + (m * 30);
            int y = nyr - yr;
            TotalDay  = d + (y * 365);
        }
</code></pre>
