{
  "id": "time-duration",
  "version": "ba7046930180",
  "status": "published",
  "name": "Time Duration Calculator",
  "question": "What is the time duration?",
  "summary": "Computes the elapsed time between two dates with times of day in days, hours, minutes, and seconds, and as total hours, minutes, and seconds.",
  "category": "days",
  "subcategory": "time-and-hours",
  "url": "https://www.acalculator.org/days/time-duration-calculator",
  "markdown": "https://www.acalculator.org/days/time-duration-calculator.md",
  "kind": "function",
  "method": "seconds = (end date − start date in days) × 86,400 + end time − start time in seconds; then split into days, hours, minutes, and seconds.",
  "assumptions": [
    "Every day has 24 hours: clock changes for daylight saving time and leap seconds are not counted.",
    "Both times are in the same time zone.",
    "Dates are on the Gregorian calendar, from 1600 to 2400, with its leap years.",
    "An end before the start gives no answer."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "startDate": {
        "title": "Start date",
        "description": "The date the period starts. Today, unless you change it.",
        "type": "string",
        "format": "date"
      },
      "startTime": {
        "title": "Start time",
        "description": "The time of day the period starts.",
        "type": "string",
        "pattern": "^\\d{2}:\\d{2}(:\\d{2})?$"
      },
      "endDate": {
        "title": "End date",
        "description": "The date the period ends.",
        "type": "string",
        "format": "date"
      },
      "endTime": {
        "title": "End time",
        "description": "The time of day the period ends.",
        "type": "string",
        "pattern": "^\\d{2}:\\d{2}(:\\d{2})?$"
      }
    }
  },
  "outputs": {
    "duration": {
      "label": "Duration",
      "description": "The time from the start to the end in whole days, hours, minutes, and seconds.",
      "format": "duration"
    },
    "hours": {
      "label": "Total hours",
      "description": "The duration in hours: seconds ÷ 3,600.",
      "format": "number"
    },
    "minutes": {
      "label": "Total minutes",
      "description": "The duration in minutes: seconds ÷ 60.",
      "format": "number"
    },
    "seconds": {
      "label": "Total seconds",
      "description": "The duration in seconds.",
      "format": "integer"
    },
    "days": {
      "label": "Total days",
      "description": "The duration in days of 24 hours: seconds ÷ 86,400.",
      "format": "number"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "startDate": "2026-09-29",
      "startTime": "09:00:00",
      "endDate": "2026-10-01",
      "endTime": "17:30:00"
    },
    "outputs": {
      "duration": {
        "days": 2,
        "hours": 8,
        "minutes": 30,
        "seconds": 0
      },
      "hours": 56.5,
      "minutes": 3390,
      "seconds": 203400,
      "days": 2.3541666666666665
    },
    "text": "From September 29, 2026 9:00:00 AM to October 1, 2026 5:30:00 PM is 56.5 hours."
  },
  "examples": [
    {
      "given": {
        "startDate": "2026-09-27",
        "startTime": "09:00:00",
        "endDate": "2026-09-29",
        "endTime": "17:30:00"
      },
      "expect": {
        "duration": {
          "days": 2,
          "hours": 8,
          "minutes": 30,
          "seconds": 0
        },
        "hours": 56.5,
        "minutes": 3390,
        "seconds": 203400,
        "days": 2.3541666666666665
      },
      "source": "hand calculation in content.mdx: 2 days + 8 h 30 min = 203,400 s"
    },
    {
      "given": {
        "startDate": "2026-12-31",
        "startTime": "23:59:30",
        "endDate": "2027-01-01",
        "endTime": "00:00:15"
      },
      "expect": {
        "duration": {
          "days": 0,
          "hours": 0,
          "minutes": 0,
          "seconds": 45
        },
        "seconds": 45,
        "minutes": 0.75
      },
      "source": "hand calculation in content.mdx: 30 s to midnight plus 15 s"
    },
    {
      "given": {
        "startDate": "2024-02-28",
        "startTime": "12:00:00",
        "endDate": "2024-03-01",
        "endTime": "12:00:00"
      },
      "expect": {
        "duration": {
          "days": 2,
          "hours": 0,
          "minutes": 0,
          "seconds": 0
        },
        "hours": 48
      },
      "source": "hand calculation in content.mdx: February 28 to March 1, 2024 is 2 days"
    },
    {
      "given": {
        "startDate": "2026-03-08",
        "startTime": "01:00:00",
        "endDate": "2026-03-08",
        "endTime": "03:00:00"
      },
      "expect": {
        "hours": 2
      },
      "source": "hand calculation in content.mdx: 3:00 − 1:00 on a 24-hour clock is 2 hours"
    }
  ],
  "sources": [
    "NIST Special Publication 811 (2008), Guide for the Use of the International System of Units: 1 d = 24 h = 86,400 s, 1 h = 3,600 s. https://www.nist.gov/pml/special-publication-811",
    "U.S. Naval Observatory, Leap Years: the Gregorian leap year rule (divisible by 4, except century years not divisible by 400). https://aa.usno.navy.mil/faq/leap_years",
    "15 U.S.C. 260a, daylight saving time: clocks advance at 2:00 AM on the second Sunday in March. https://www.law.cornell.edu/uscode/text/15/260a"
  ],
  "related": [
    "hours",
    "time",
    "days-between-dates",
    "work-hours"
  ],
  "changelog": []
}
