Click here to Skip to main content
15,921,694 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created an ajax timer in a asp.net page. It's showing current time, in the short time format (9:33 AM) and its running.

When I clicked on a button, current clock time displays on a textbox, and on another button click the current time displays in another textbox.

For example if the value in the first textbox is 9:23 and second textbox is 9:30; How can I calculate the time difference?

9:30 - 9:23 = 0:07

Help me to find the time difference.
Posted
Updated 8-Feb-11 17:18pm
v2

HOW To Calculate intime and outtime in employmet status using asp.net and c#.net coding using mysql
 
Share this answer
 
Hope How-find-difference-between-two-Dates[^]may also help you.
 
Share this answer
 
The structure System.DateTime has "-" (subtraction operator) defined, return type is System.TimeSpan.

See http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

This should be more then enough.

—SA
 
Share this answer
 
Comments
[no name] 8-Feb-11 23:51pm    
Good call Sakryukov.
Abhinav S 8-Feb-11 23:56pm    
IMO, This is the best link. 5.
Sergey Alexandrovich Kryukov 9-Feb-11 15:44pm    
Well, thank you,
--SA
JF2015 9-Feb-11 0:56am    
Good answer without helping too much. I like that you do not provide completely ready solutions but hints for the OP for where to search for solutions.
Sergey Alexandrovich Kryukov 9-Feb-11 15:44pm    
Thank you, I knew you would appreciate this :-)
In other cases, detail background is better, not here.
--SA
This[^] may help.
 
Share this answer
 
Comments
[no name] 8-Feb-11 23:50pm    
Good call Abhinav
Abhinav S 8-Feb-11 23:56pm    
Thanks.
[no name] 9-Feb-11 0:06am    
Welcome Abhinav.
Hi,

MSIL
DateTime dateTime1 = Convert.ToDateTime("9:30");
DateTime dateTime2 = Convert.ToDateTime("9:23");
TimeSpan timeSpan=dateTime1.Subtract(dateTime2);


Note: As the time string don't have AM or PM the conversion will take it as a 24 hr clock
 
Share this answer
 
Comments
Abhinav S 8-Feb-11 23:27pm    
Good answer.
[no name] 8-Feb-11 23:50pm    
Good Call.
JF2015 9-Feb-11 0:56am    
Correct answer. 5+

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