Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript
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 15-Mar-13 5:17am
Comments
Sergey Alexandrovich Kryukov at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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)[^]
  Permalink  
Comments
Maciej Los at 15-Mar-13 16:34pm
   
+5!
Sandeep Mewara at 15-Mar-13 16:41pm
   
Thanks Mac. :)
Ganesh_mca at 18-Mar-13 3:22am
   
Timespan is not working at Eclipse script files(Netsuite scripts)
Sandeep Mewara at 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)

  Print Answers RSS
0 OriginalGriff 230
1 PIEBALDconsult 150
2 DamithSL 125
3 Andreas Gieriet 90
4 Jochen Arndt 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 15 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100