Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Minute difference between two arbitrary string values
function CountingMinutesI(str) {
var times = str.replace(";\"","").split("-").map(function(t) {
t = t.split(":");
var h = parseInt(t[0], 10);
var m = parseInt(t[1], 10);
var am = t[1].indexOf("am") > 0;
if(h === 12) h = 0;
var mins = m + h * 60;
if(!am) mins += 720;
return mins;
});
var diff = times[1] - times[0];
return diff > 0 ? diff : diff + 1440;
}
@egeozcan

This comment has been minimized.

Copy link
Owner Author

egeozcan commented May 15, 2012

Use it like:
CountingMinutesI("12:05am-02:55pm")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.