≡ Menu




How do I find difference between two dates? In C#

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
Response.Write( “Time Difference: <br/> “
);
Response.Write
(diffDate.Days.ToString() + ” Days <br/>”
);
Response.Write
(diffDate.Hours.ToString() + ” Hours <br/>”
);
Response.Write
(diffDate.Minutes.ToString() + ” Minutes <br/>”
);
Response.Write
(diffDate.Seconds.ToString() + ” Seconds <br/> “
);
Response.Write
(diffDate.Milliseconds.ToString() + ” Milliseconds <br/>”);

{ 0 comments… add one }

Leave a Comment