date calculator code example
Example 1: date difference
function daysBetween(first, second) {
var one = new Date(first.getFullYear(), first.getMonth(), first.getDate());
var two = new Date(second.getFullYear(), second.getMonth(), second.getDate());
var millisecondsPerDay = 1000 * 60 * 60 * 24;
var millisBetween = two.getTime() - one.getTime();
var days = millisBetween / millisecondsPerDay;
return Math.floor(days);
}
Example 2: calculate total time from start and end datetime
var date1 = new Date('2019-02-27T23:34:25');
var date2 = new Date('2019-02-28T15:55:38');
var ElapsedSeconds = (date2 - date1) / 1000;