The solution is easy but I have seen developers using different ways to find out difference between two dates by comparing the DateTime members.
The easy solution is to use the TimeSpan class and its members.
DateTime.Subtract method returns a TimeSpan object, which has properties such as Days, Hours, Minutes and so on to get the difference in specific measurements.
Here is code snippet:
// Start date
DateTime startDate = new DateTime(2005, 2, 1, 3, 4, 12, 56);
// End date
DateTime endDate = new DateTime(2005, 12, 12, 4, 30, 45, 12);
// Time span
TimeSpan diffDate = endDate.Subtract ( startDate );
// Spit it out
Console.WriteLine( "Time Difference: ");
Console.WriteLine(diffDate.Days.ToString() + " Days");
Console.WriteLine(diffDate.Hours.ToString() + " Hours" );
Console.WriteLine(diffDate.Minutes.ToString() + " Minutes");
Console.WriteLine(diffDate.Seconds.ToString() + " Seconds ");
Console.WriteLine(diffDate.Milliseconds.ToString() + " Milliseconds ");

Mahesh ChandPosted Jan 28, 2011, 10:28 AM
Ok I have just published a detailed DateTime tutorial. Here is the URL: http://www.c-sharpcorner.com/UploadFile/mahesh/5242/Default.aspx
om dudhagundiPosted Oct 3, 2010, 10:34 AM
hi mahesh this is goo one....but i am doing one lodge application i want to store date & time in DB SQL server 2005 & take a diffrence can u help me?
omkar dongrePosted Jan 6, 2010, 8:48 AM
it worked!
asilPosted Dec 25, 2008, 10:25 AM
I wonder how the code, countdown the shown date time.