Click here to Skip to main content
13,190,994 members (56,395 online)
Rate this:
Please Sign up or sign in to 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?

Posted 15-Mar-13 4:17am
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.

1 solution

Rate this: bad
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.

MSDN: TimeSpan Structure[^]
MSDN: TimeSpan.Parse Method (String)[^]
Maciej Los 15-Mar-13 16:34pm
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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171016.2 | Last Updated 15 Mar 2013
Copyright © CodeProject, 1999-2017
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