Duration Calculator/ years · months · days · hours · minutes
Calculate the exact difference between two dates or times — broken down into years, months, days, hours, minutes, and seconds, plus total days and weeks.
Start
End
Duration from Start to End
1
yr
Years
0
mo
Months
0
d
Days
0
hr
Hours
0
min
Minutes
0
sec
Seconds
365
Total Days
52
Total Weeks
8,760
Total Hours
525,600
Total Minutes
Did this tool solve your problem?
Code Examples
JavaScript (date-fns)
import {
differenceInYears, differenceInMonths,
differenceInDays, differenceInHours,
formatDistanceToNow, intervalToDuration,
format
} from 'date-fns';
const start = new Date('2020-01-15');
const end = new Date('2024-06-30');
differenceInYears(end, start) // 4
differenceInDays(end, start) // 1628
differenceInHours(end, start) // 39072
// Human-readable breakdown
intervalToDuration({ start, end })
// { years:4, months:5, days:15, hours:0, ... }
// Relative time
formatDistanceToNow(start, { addSuffix: true })
// "about 4 years ago"Python
from datetime import datetime, date from dateutil.relativedelta import relativedelta start = datetime(2020, 1, 15) end = datetime(2024, 6, 30) # Total difference diff = end - start diff.days # 1628 diff.total_seconds() / 3600 # 39072.0 # Calendar-aware breakdown (pip install python-dateutil) delta = relativedelta(end, start) delta.years # 4 delta.months # 5 delta.days # 15 # Age calculation birthday = date(1990, 5, 20) today = date.today() age = relativedelta(today, birthday).years
Go
import (
"fmt"
"time"
)
start := time.Date(2020, 1, 15, 0, 0, 0, 0, time.UTC)
end := time.Date(2024, 6, 30, 0, 0, 0, 0, time.UTC)
duration := end.Sub(start)
fmt.Println(duration.Hours() / 24) // 1628 days
fmt.Println(duration.Hours()) // 39072 hours
// Calendar diff (years/months) — manual calculation
years := end.Year() - start.Year()
months := int(end.Month()) - int(start.Month())
if months < 0 {
years--
months += 12
}
fmt.Printf("%d years, %d months\n", years, months)SQL
-- MySQL / MariaDB
SELECT
DATEDIFF('2024-06-30', '2020-01-15') AS days,
TIMESTAMPDIFF(YEAR, '2020-01-15', '2024-06-30') AS years,
TIMESTAMPDIFF(MONTH, '2020-01-15', '2024-06-30') AS months,
TIMESTAMPDIFF(HOUR, '2020-01-15', '2024-06-30') AS hours;
-- PostgreSQL
SELECT
'2024-06-30'::date - '2020-01-15'::date AS days,
AGE('2024-06-30', '2020-01-15') AS human_readable;
-- 4 years 5 mons 15 days
-- SQLite
SELECT julianday('2024-06-30') - julianday('2020-01-15');
-- 1628.0Frequently Asked Questions
Why can't I just divide milliseconds to get years/months/days?
Dividing milliseconds gives exact total durations but not the intuitive "X years, Y months, Z days" breakdown. Month lengths vary (28–31 days) and leap years exist. This tool uses a calendar-aware algorithm to match everyday intuition.
How do I calculate someone's age or work tenure?
Enter the birth date or start date as "Start" and today as "End" — the result shows exact years with remaining months and days.
How many business days are between two dates?
Business day calculation is more complex: you must exclude weekends, and optionally holidays. Basic algorithm: iterate through the date range, skip Saturdays and Sundays. For production, use a library like date-fns differenceInBusinessDays.
Do leap seconds affect duration calculations?
No, for ordinary date calculations. JavaScript's Date object and most OS time systems do not account for leap seconds. Leap seconds only matter for highly precise timing and require specialized TAI-time libraries.
How do I display relative time (like "3 days ago") in JavaScript?
Use the Intl.RelativeTimeFormat API (native in modern browsers): const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' }); rtf.format(-3, 'day') → '3 days ago'. Or use date-fns formatDistanceToNow().
How do I calculate time differences across time zones?
JavaScript's Date object stores UTC timestamps internally; time zone info is only applied when displaying. Subtracting getTime() values gives the correct difference regardless of time zone.