{
  "id": "time",
  "version": "42ce2b70bc5f",
  "status": "published",
  "name": "Time Calculator",
  "question": "How do I add or subtract times?",
  "summary": "Adds or subtracts two durations in days, hours, minutes, and seconds, or adds or subtracts a duration from a date and time of day.",
  "category": "days",
  "subcategory": "time-and-hours",
  "url": "https://www.acalculator.org/days/time-calculator",
  "markdown": "https://www.acalculator.org/days/time-calculator.md",
  "kind": "function",
  "method": "Two durations: seconds = days × 86,400 + hours × 3,600 + minutes × 60 + seconds for each, then add or subtract and split back into days, hours, minutes, and seconds. From a date and time: move the start by the duration in seconds.",
  "assumptions": [
    "Every day has 24 hours: daylight saving clock changes and leap seconds are not counted.",
    "Empty boxes count as 0. Decimals are allowed (1.5 hours is 1 hour 30 minutes).",
    "A subtraction that goes below 0 gives a negative duration, shown with a minus sign.",
    "The seconds are added or subtracted unrounded, then rounded once: a duration result to the millisecond, a date and time result to the nearest second. A seconds part of the start time is kept."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "mode": {
        "title": "What do you want to do?",
        "description": "Add or subtract two durations, or add or subtract a duration from a date and time.",
        "type": "string",
        "enum": [
          "durations",
          "clock"
        ]
      },
      "aDays": {
        "title": "Days (first duration)",
        "description": "The days of the first duration. Leave it empty for 0.",
        "type": "number",
        "minimum": 0,
        "maximum": 100000
      },
      "aHours": {
        "title": "Hours (first duration)",
        "description": "The hours of the first duration. Leave it empty for 0.",
        "type": "number",
        "minimum": 0,
        "maximum": 1000000
      },
      "aMinutes": {
        "title": "Minutes (first duration)",
        "description": "The minutes of the first duration. Leave it empty for 0.",
        "type": "number",
        "minimum": 0,
        "maximum": 10000000
      },
      "aSeconds": {
        "title": "Seconds (first duration)",
        "description": "The seconds of the first duration. Leave it empty for 0.",
        "type": "number",
        "minimum": 0,
        "maximum": 1000000000
      },
      "startDate": {
        "title": "Start date",
        "description": "The date to start from. Today, unless you change it.",
        "type": "string",
        "format": "date"
      },
      "startTime": {
        "title": "Start time",
        "description": "The time of day to start from.",
        "type": "string",
        "pattern": "^\\d{2}:\\d{2}(:\\d{2})?$"
      },
      "op": {
        "title": "Add or subtract?",
        "description": "Whether to add the second duration or subtract it.",
        "type": "string",
        "enum": [
          "add",
          "subtract"
        ]
      },
      "bDays": {
        "title": "Days to add or subtract",
        "description": "The days of the duration to add or subtract. Leave it empty for 0.",
        "type": "number",
        "minimum": 0,
        "maximum": 100000
      },
      "bHours": {
        "title": "Hours to add or subtract",
        "description": "The hours of the duration to add or subtract. Leave it empty for 0.",
        "type": "number",
        "minimum": 0,
        "maximum": 1000000
      },
      "bMinutes": {
        "title": "Minutes to add or subtract",
        "description": "The minutes of the duration to add or subtract. Leave it empty for 0.",
        "type": "number",
        "minimum": 0,
        "maximum": 10000000
      },
      "bSeconds": {
        "title": "Seconds to add or subtract",
        "description": "The seconds of the duration to add or subtract. Leave it empty for 0.",
        "type": "number",
        "minimum": 0,
        "maximum": 1000000000
      }
    }
  },
  "outputs": {
    "result": {
      "label": "Result",
      "description": "The sum or difference of the two durations in days, hours, minutes, and seconds; or the date and time reached.",
      "format": "text"
    },
    "endDate": {
      "label": "Date",
      "description": "The date reached from the start date and time.",
      "format": "date-long"
    },
    "endTime": {
      "label": "Time",
      "description": "The time of day reached, on a 12-hour clock.",
      "format": "time"
    },
    "totalDays": {
      "label": "In days",
      "description": "The result of the two durations in days: seconds ÷ 86,400.",
      "format": "number"
    },
    "totalHours": {
      "label": "In hours",
      "description": "The result of the two durations in hours: seconds ÷ 3,600.",
      "format": "number"
    },
    "totalMinutes": {
      "label": "In minutes",
      "description": "The result of the two durations in minutes: seconds ÷ 60.",
      "format": "number"
    },
    "totalSeconds": {
      "label": "In seconds",
      "description": "The result of the two durations in seconds.",
      "format": "number"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "mode": "durations",
      "startDate": "2026-09-29",
      "startTime": "09:00:00",
      "op": "add",
      "aHours": 2,
      "aMinutes": 45,
      "aSeconds": 30,
      "bHours": 1,
      "bMinutes": 30,
      "bSeconds": 45
    },
    "outputs": {
      "result": "4 hours, 16 minutes, 15 seconds",
      "totalDays": 0.1779513888888889,
      "totalHours": 4.270833333333333,
      "totalMinutes": 256.25,
      "totalSeconds": 15375
    },
    "text": "The answer is 4 hours, 16 minutes, 15 seconds."
  },
  "examples": [
    {
      "given": {
        "mode": "durations",
        "aHours": 2,
        "aMinutes": 45,
        "aSeconds": 30,
        "op": "add",
        "bHours": 1,
        "bMinutes": 30,
        "bSeconds": 45
      },
      "expect": {
        "result": "4 hours, 16 minutes, 15 seconds",
        "totalSeconds": 15375,
        "totalMinutes": 256.25
      },
      "source": "hand calculation in content.mdx: 30 + 45 = 75 s = 1 min 15 s; 45 + 30 + 1 = 76 min = 1 h 16 min; 2 + 1 + 1 = 4 h"
    },
    {
      "given": {
        "mode": "durations",
        "aDays": 1,
        "aHours": 3,
        "op": "subtract",
        "bHours": 5,
        "bMinutes": 20
      },
      "expect": {
        "result": "21 hours, 40 minutes",
        "totalHours": 21.666666666666668
      },
      "source": "hand calculation in content.mdx: 27 h − 5 h 20 min = 21 h 40 min"
    },
    {
      "given": {
        "mode": "durations",
        "aMinutes": 90,
        "op": "subtract",
        "bHours": 2
      },
      "expect": {
        "result": "-30 minutes",
        "totalSeconds": -1800
      },
      "source": "hand calculation in content.mdx: 90 min − 120 min = −30 min"
    },
    {
      "given": {
        "mode": "durations",
        "aHours": 1.5,
        "op": "add",
        "bMinutes": 0.25
      },
      "expect": {
        "result": "1 hour, 30 minutes, 15 seconds",
        "totalSeconds": 5415
      },
      "source": "hand calculation in content.mdx: 1.5 h = 5,400 s; 0.25 min = 15 s"
    },
    {
      "given": {
        "mode": "clock",
        "startDate": "2026-09-27",
        "startTime": "22:30:00",
        "op": "add",
        "bHours": 8,
        "bMinutes": 45
      },
      "expect": {
        "result": "Monday, September 28, 2026, 7:15:00 AM",
        "endDate": "2026-09-28",
        "endTime": "07:15:00"
      },
      "source": "hand calculation in content.mdx: 22:30 + 8:45 = 31:15, which is 7:15 the next day"
    },
    {
      "given": {
        "mode": "clock",
        "startDate": "2026-03-01",
        "startTime": "06:00:00",
        "op": "subtract",
        "bDays": 1,
        "bHours": 7
      },
      "expect": {
        "endDate": "2026-02-27",
        "endTime": "23:00:00"
      },
      "source": "hand calculation in content.mdx: back 1 day to February 28, 6:00 AM, then 7 hours to 11:00 PM on February 27"
    }
  ],
  "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 = 60 min = 3,600 s. https://www.nist.gov/pml/special-publication-811",
    "U.S. Naval Observatory, Leap Years: the Gregorian leap year rule. https://aa.usno.navy.mil/faq/leap_years"
  ],
  "related": [
    "hours",
    "time-duration",
    "date"
  ],
  "changelog": [
    {
      "date": "2026-09-28",
      "note": "Each duration box names its duration, for example “Hours (first duration)”."
    }
  ]
}
