Enter your start and end times to find the total elapsed time.
Total Time:
Decimal Hours: hrs
Total Hours Accumulator
Add multiple blocks of time to calculate a weekly or project total.
Grand Total:
Total Decimal: hrs
function calculateDuration() {
var start = document.getElementById('startTime').value;
var end = document.getElementById('endTime').value;
var breakMin = parseInt(document.getElementById('breakMinutes').value) || 0;
if (!start || !end) {
alert("Please enter both start and end times.");
return;
}
var startParts = start.split(':');
var endParts = end.split(':');
var startTotalMinutes = (parseInt(startParts[0]) * 60) + parseInt(startParts[1]);
var endTotalMinutes = (parseInt(endParts[0]) * 60) + parseInt(endParts[1]);
// Handle overnight wrap-around
if (endTotalMinutes < startTotalMinutes) {
endTotalMinutes += 1440; // 24 hours in minutes
}
var diffMinutes = endTotalMinutes – startTotalMinutes – breakMin;
if (diffMinutes < 0) {
diffMinutes = 0;
}
var h = Math.floor(diffMinutes / 60);
var m = diffMinutes % 60;
var decimal = (diffMinutes / 60).toFixed(2);
document.getElementById('totalTimeStr').innerText = h + "h " + m + "m";
document.getElementById('decimalTimeStr').innerText = decimal;
document.getElementById('durationResult').style.display = 'block';
}
function addRow() {
var container = document.getElementById('hoursRows');
var div = document.createElement('div');
div.className = 'hours-row';
div.style.display = 'grid';
div.style.gridTemplateColumns = '1fr 1fr';
div.style.gap = '15px';
div.style.marginBottom = '10px';
div.innerHTML = '' +
";
container.appendChild(div);
}
function accumulateHours() {
var hInputs = document.getElementsByClassName('row-h');
var mInputs = document.getElementsByClassName('row-m');
var totalMin = 0;
for (var i = 0; i < hInputs.length; i++) {
var hours = parseInt(hInputs[i].value) || 0;
var minutes = parseInt(mInputs[i].value) || 0;
totalMin += (hours * 60) + minutes;
}
var finalH = Math.floor(totalMin / 60);
var finalM = totalMin % 60;
var finalDecimal = (totalMin / 60).toFixed(2);
document.getElementById('sumTimeStr').innerText = finalH + "h " + finalM + "m";
document.getElementById('sumDecimalStr').innerText = finalDecimal;
document.getElementById('accumulatorResult').style.display = 'block';
}
How to Calculate Hours Effectively
Calculating work hours manually can lead to errors in payroll or project management. The most common way to calculate total time is by converting time into minutes, performing the math, and then converting it back to hours and minutes or decimal format.
Understanding Decimal Hours
For payroll purposes, you often need to convert minutes into a decimal. This is done by dividing the minutes by 60. For example:
15 minutes = 15/60 = 0.25 hours
30 minutes = 30/60 = 0.50 hours
45 minutes = 45/60 = 0.75 hours
Steps for Manual Calculation
Identify Start and End Times: Note the exact time you began and finished.
Subtract Breaks: Always deduct unpaid lunch breaks or personal time.
Convert to 24-Hour Format: If working across PM to AM (night shifts), use a 24-hour clock to avoid confusion (e.g., 10:00 PM is 22:00).
Total the Minutes: Add up all hours and minutes separately, then simplify (e.g., 120 minutes becomes 2 hours).
Example Work Calculation
If an employee starts at 8:30 AM and leaves at 5:15 PM with a 45-minute lunch break:
Total Duration (8:30 to 17:15) = 8 hours and 45 minutes.
Minus 45-minute break = 8 hours total.
Decimal representation = 8.00 hours.
Disclaimer: This calculator is for informational purposes only. Always verify your hours with your official company time-tracking software.