I have the following code that now calculates the correct minutes, but the days does not calculate correctly. Also, needed help added code that will calculate mon-fri only and exclude sat/sun.
Date format I used subtract(DDMMYYY) : 01/01/2015 20:21 - 01/01/2015 20:22. This returns 4.1 using the code below. The ".1" is correct, one minute difference. The 4 is incorrect as its not more than a day.
Note - I searched other threads and couldnt find the solution. my code is below:
function stringToDate(s) {
var dateParts = s.split(' ')[0].split('/');
var timeParts = s.split(' ')[1].split(':');
var d = new Date(dateParts[0], --dateParts[1], dateParts[2]);
d.setHours(timeParts[0], timeParts[1]);
return d;
}
function test() {
var a = slat_1.value;
var b = slar_1.value;
var x = (new Date(stringToDate(a) - stringToDate(b)));
//converting milliseconds
x = 1000*Math.round(x/1000); // round to nearest second
var d = new Date(x);
alert( d.getUTCDay() + '.' + d.getUTCMinutes() );
}