Click here to Skip to main content
15,913,250 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have start time and end time and i want to calculate total time.

start time 7.00AM

Total time 10.00AM


End time i want the answer 3


please help me
Posted

This is simple math. Total time is always EndTime - StartTime.

If you subtrace one datetime value from another then result is a TimeSpan object with the "total time" as you call it.
 
Share this answer
 
Assuming the starttime and end times are both of type DateTime:
C#
TimeSpan span = endTime - StartTime;

At this point, you can use the properties in the TimeSpan object to determine the amount of time.
 
Share this answer
 
Try:

C#
DateTime start = new DateTime(1, 1, 1, 7, 0, 0);
DateTime end = new DateTime(1, 1, 1, 10, 0, 0);
TimeSpan ts = end - start;
int diffHours = ts.Hours;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900