Skip to content
🛠️ToolsShed

Working Hours Calculator

Calculate total working hours per day and week with break time deductions.

#StartEndBreak (min)Hours
108:00
208:00
308:00
408:00
508:00

Weekly total

40:00

Overtime (>8h/day)

00:00

About this tool

The Working Hours Calculator helps employees and managers accurately track total work time by deducting breaks and meal periods from the workday. Whether you're managing shift schedules, verifying payroll hours, or simply monitoring your own time, this tool quickly computes daily and weekly totals so you have a clear picture of actual hours worked.

To use the calculator, enter your start and end times for each workday, specify the duration of any breaks (lunch, coffee breaks, or unpaid periods), and the tool will automatically subtract these from your total duration. It supports multiple breaks per day and generates both daily and cumulative weekly summaries, making it easy to spot patterns or discrepancies.

This tool is particularly valuable for contract workers, freelancers tracking billable hours, and HR professionals ensuring compliance with labor regulations. The simple interface accommodates various shift patterns—early mornings, late nights, split shifts—and the weekly view helps identify overtime or scheduling issues at a glance.

Frequently Asked Questions

Code Implementation

from datetime import datetime, timedelta

def working_hours(start: datetime, end: datetime, break_minutes: int = 0) -> dict:
    """Calculate working hours between two datetimes, subtracting break time."""
    if end < start:
        raise ValueError("End time must be after start time")
    total_seconds = (end - start).total_seconds()
    worked_seconds = max(0, total_seconds - break_minutes * 60)
    hours = int(worked_seconds // 3600)
    minutes = int((worked_seconds % 3600) // 60)
    return {
        "total_hours": worked_seconds / 3600,
        "formatted": f"{hours}h {minutes:02d}m",
        "break_hours": break_minutes / 60,
        "gross_hours": total_seconds / 3600,
    }

def weekly_hours(shifts: list[dict]) -> dict:
    """Calculate total working hours across multiple shifts."""
    total_seconds = 0
    for shift in shifts:
        start = datetime.strptime(shift["start"], "%Y-%m-%d %H:%M")
        end = datetime.strptime(shift["end"], "%Y-%m-%d %H:%M")
        result = working_hours(start, end, shift.get("break_minutes", 0))
        total_seconds += result["total_hours"] * 3600

    h = int(total_seconds // 3600)
    m = int((total_seconds % 3600) // 60)
    return {"total_hours": total_seconds / 3600, "formatted": f"{h}h {m:02d}m"}

# Example
shifts = [
    {"start": "2024-01-15 09:00", "end": "2024-01-15 17:30", "break_minutes": 60},
    {"start": "2024-01-16 08:30", "end": "2024-01-16 16:00", "break_minutes": 30},
]
result = weekly_hours(shifts)
print(f"Total: {result['formatted']} ({result['total_hours']:.2f} hours)")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.