Question

I need to subtract minutes from the calculated time

var calculatedTime=11.30;// hours
var subtractTime=40;//minutes
var diff=calculatedTime - subtractTime;// How to do this ??

How to do this in javascript

Thanks

Was it helpful?

Solution

Try this:

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

function parseTime(s) {
    return Math.floor(parseInt(s) / 60) + "." + parseInt(s) % 60
}
//var minutes = parseTime(EndTIme) - parseTime(StartTime);

var timeToSubtract = 40;
var startTime = converToMinutes('11.30');
var converted = parseTime(startTime - timeToSubtract);
alert(converted);

Demo here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top