I want to show difference between two time like 11 : 00 PM to 09 : 00 AM !
how ??
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Oct 13, 2014, 7:05 AM EDT
DateTime dt1 = DateTime.Parse("11 : 00 PM");
DateTime dt2 = DateTime.Parse("09 : 00 AM");
TimeSpan ts = dt2 - dt1;
double hours = ts.TotalHours;
if (hours < 0) hours += 24;
Console.WriteLine(hours); // 10
I'm assuming that order is important here. So you're wanting to go from 11 PM one day to 9 AM the next day.
Rizwan Fancy34 reputationPosted Oct 13, 2014, 7:33 AM EDT
Rizwan Fancy34 reputationPosted Oct 13, 2014, 7:33 AM EDT
Munesh SharmaRank #174 · 13.9K reputationPosted Oct 13, 2014, 8:48 PM EDT
string endTime = "11 : 00 PM";
TimeSpan duration = DateTime.Parse(endTime).Subtract(DateTime.Parse(startTime));
Console.WriteLine(duration);
Console.ReadKey();