Calculate total shift time, decimal hours, and earnings with ease.
Work Summary
How to Calculate Hours Worked
Tracking your work hours accurately is essential for both employees and freelancers to ensure fair compensation and productivity management. This Hours Worked Calculator simplifies the process of subtracting breaks and handling shifts that cross over midnight.
The Basic Formula
To calculate your work duration manually, use the following steps:
Determine the Total Elapsed Time: Subtract the start time from the end time.
Subtract Breaks: Deduct any unpaid lunch or rest periods from the total elapsed time.
Convert to Decimal: Since most payroll systems use decimal hours (e.g., 7.5 hours instead of 7 hours and 30 minutes), divide the remaining minutes by 60 and add them to the total hours.
Example Calculation:
Start Time: 8:30 AM | End Time: 5:15 PM | Break: 45 minutes
1. Elapsed Time: 8 hours and 45 minutes.
2. Minus Break: 8 hours and 0 minutes.
3. Decimal Format: 8.00 hours.
Handling Night Shifts
If your shift starts in the evening (e.g., 10:00 PM) and ends the next morning (e.g., 6:00 AM), our calculator automatically detects the day change. Mathematically, you add 24 hours to the end time if it is numerically "smaller" than the start time to get the correct duration.
Converting Minutes to Decimals
For your records, here is a quick conversion guide for common minute intervals:
15 minutes = 0.25 hours
30 minutes = 0.50 hours
45 minutes = 0.75 hours
function calculateHoursWorked() {
var startTime = document.getElementById('startTime').value;
var endTime = document.getElementById('endTime').value;
var breakMin = parseFloat(document.getElementById('breakMinutes').value) || 0;
var hourlyRate = parseFloat(document.getElementById('hourlyRate').value) || 0;
if (!startTime || !endTime) {
alert("Please enter both start and end times.");
return;
}
var startParts = startTime.split(':');
var endParts = endTime.split(':');
var startTotalMinutes = (parseInt(startParts[0]) * 60) + parseInt(startParts[1]);
var endTotalMinutes = (parseInt(endParts[0]) * 60) + parseInt(endParts[1]);
// Handle overnight shifts
if (endTotalMinutes < startTotalMinutes) {
endTotalMinutes += 24 * 60;
}
var totalWorkMinutes = endTotalMinutes – startTotalMinutes – breakMin;
if (totalWorkMinutes < 0) {
alert("Break duration cannot exceed total shift time.");
return;
}
var hours = Math.floor(totalWorkMinutes / 60);
var minutes = totalWorkMinutes % 60;
var decimalHours = totalWorkMinutes / 60;
var resultArea = document.getElementById('resultArea');
var displayTotalTime = document.getElementById('displayTotalTime');
var displayDecimal = document.getElementById('displayDecimal');
var displayPay = document.getElementById('displayPay');
resultArea.style.display = 'block';
displayTotalTime.innerHTML = "Total Time: " + hours + "h " + minutes + "m";
displayDecimal.innerHTML = "Decimal Hours: " + decimalHours.toFixed(2) + " hours";
if (hourlyRate > 0) {
var totalPay = decimalHours * hourlyRate;
displayPay.innerHTML = "Estimated Pay: $" + totalPay.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
} else {
displayPay.innerHTML = "";
}
}