how to calculate total time i have start time and end time.
start time 9.30 AM
End time 4.30 Pm
Total time
in total time i want to calculate how many hours they worked.
Time difference
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Pramod Kumar NandagiriRank #6,963 · 252 reputationPosted Feb 23, 2012, 6:31 AM EST
{
DateTime dt1 = Convert.ToDateTime("9:30 am");
DateTime dt2 = Convert.ToDateTime("10:00 pm");
TimeSpan ts = dt2 - dt1;
Response.Write(ts.ToString());
}
if the time difference gores more than one day you can get hours by
ts.hours.tostring(); and minuts by
ts.minuts.tostring();
Please don't forget mark the thread as "Accepted Answer" if it helps you..
VulpesRank #55 · 29.2K reputationPosted Feb 23, 2012, 6:50 AM EST
Also, if the times are to be presented in exactly that format (i.e. separated by a dot instead of a colon), then you'll need to specify the format to be used, otherwise you'll get an exception:
string format = "h.m tt";
DateTime startTime = DateTime.ParseExact("9.30 AM", format, null);
DateTime endTime = DateTime.ParseExact("4.30 Pm", format, null);
double totalTime = (endTime - startTime).TotalHours;
Response.Write(String.Format("Total time worked is {0} hours", totalTime));