Click here to Skip to main content
15,888,246 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi how to calculate total time from two text boxes in another text box when i click total time button..?

example: 1st textbox 9:00am 2nd textbox 11:00am 3rd textbox when i click button should display 2hours.how to do this..any one help??
Posted
Comments
Sergey Alexandrovich Kryukov 30-Jan-12 0:54am    
Time can be calculated between some events, not "text boxes". So, between what events?
--SA

 
Share this answer
 
Comments
ythisbug 30-Jan-12 0:17am    
not this type of examples..just i want to calculate total hour spent for work..suppose time in is 9am and time out is 6 pm in third text box i want to count total time work.button click or in javascript?
DateTime startTime = DateTime.Now;

DateTime endTime = DateTime.Now.AddSeconds( 75 );

TimeSpan span = endTime.Subtract ( startTime );
Console.WriteLine( "Time Difference (seconds): " + span.Seconds );
Console.WriteLine( "Time Difference (minutes): " + span.Minutes );
Console.WriteLine( "Time Difference (hours): " + span.Hours );
Console.WriteLine( "Time Difference (days): " + span.Days );
 
Share this answer
 
Comments
ythisbug 29-Jan-12 23:24pm    
no need of putting text box id?i want answer like this firsttextbox-secondtextbox=thirdtextbox.
HarisJayadev 29-Jan-12 23:37pm    
TimeSpan span = Convert.ToDateTime(TxtBox2.Text).Subtract(TxtBox2.Text)

TextBox3.Text = span.Hours.ToString() + span.Minutes.ToString() + span.Seconds.ToString()
ythisbug 30-Jan-12 0:18am    
not this type of examples..just i want to calculate total hour spent for work..suppose time in is 9am and time out is 6 pm in third text box i want to count total time work.button click or in javascript?

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