Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
64
rated 0 times [  66] [ 2]  / answers: 1 / hits: 15155  / 15 Years ago, tue, december 22, 2009, 12:00:00

For Example:



StartTime = '00:10';
EndTIme = '01:20';


These variables are string



Question: How can I Subtract them and returning the span time in minutes?



Hope you can help


More From » javascript

 Answers
88

Make a function to parse a string like that into minutes:



function parseTime(s) {
var c = s.split(':');
return parseInt(c[0]) * 60 + parseInt(c[1]);
}


Now you can parse the strings and just subtract:



var minutes = parseTime(EndTIme) - parseTime(StartTime);

[#98017] Friday, December 18, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jayla

Total Points: 14
Total Questions: 96
Total Answers: 123

Location: Greenland
Member since Fri, Jul 31, 2020
4 Years ago
;