Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HI All,

I have problem with calculating duration between times as strings,

times like ex:

var time1 = '10:32';

var time2 = '12:57';

and i want to calculate time2 - time1?with total hours and mins

please help me asap?


Thanks
Ganesh
Posted
Comments
Sergey Alexandrovich Kryukov 15-Mar-13 10:25am    
You should compare time instead of string. First to think about is how you ended up having these strings. You should not have it in first place.
—SA

1 solution

Take that string and convert it into TimeSpan field and then take the difference.

Read about TimeSpan. You need to find the difference between the to time and the from time. Using Timespan, you get the difference in terms of hours/minutes/seconds, etc.

Refer:
MSDN: TimeSpan Structure[^]
MSDN: TimeSpan.Parse Method (String)[^]
 
Share this answer
 
Comments
Maciej Los 15-Mar-13 16:34pm    
+5!
Sandeep Mewara 15-Mar-13 16:41pm    
Thanks Mac. :)
Ganesh_mca 18-Mar-13 3:22am    
Timespan is not working at Eclipse script files(Netsuite scripts)
Sandeep Mewara 18-Mar-13 5:42am    
http://msdn.microsoft.com/en-us/library/ie/ff743760%28v=vs.94%29.aspx

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