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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Munesh SharmaPosted Oct 14, 2014, 12:48 AM
string endTime = "11 : 00 PM";
TimeSpan duration = DateTime.Parse(endTime).Subtract(DateTime.Parse(startTime));
Console.WriteLine(duration);
Console.ReadKey();
Rizwan FancyPosted Oct 13, 2014, 11:33 AM
Rizwan FancyPosted Oct 13, 2014, 11:33 AM
VulpesPosted Oct 13, 2014, 11:05 AM
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.