How do I Get the diffrence between two dates

By karan patel

Here i wil show how you can difference between two dates in number of days, hour, minutes, seconds, milliseconds.

            //starting date.. assign any date
           DateTime startdate = DateTime.Now;

             // End date .. assign any date
           DateTime enddate = DateTime.Now.AddDays(10);

             // Substract datetime returns Time span
           TimeSpan diff = enddate.Subtract(startdate);

             MessageBox.Show("Total Days" + diff.Days.ToString());
             MessageBox.Show("Total Hours " + diff.Hours.ToString());
             MessageBox.Show("Total Minutes " + diff.Minutes.ToString());
             MessageBox.Show("Total Seconds " + diff.Seconds.ToString());
             MessageBox.Show("Total Milliseconds " + diff.Milliseconds.ToString());

How do I Get the diffrence between two dates  (1137 Views)