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.
Loading
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.
VulpesPosted Feb 23, 2012, 11:50 AM
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));
Pramod Kumar NandagiriPosted Feb 23, 2012, 11:31 AM
{
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..