Guide
How to Add and Subtract Date and Time
Reliable date-and-time arithmetic separates variable-length calendar months from exact civil seconds.
1. Validate the civil date and clock
The date must be a real proleptic-Gregorian YYYY-MM-DD value. The clock must use HH:MM or HH:MM:SS. No timezone or UTC offset is attached.
2. Apply years and months once
Convert Years and Months into one calendar-month displacement. Move the Year and Month once, then preserve the original day when it exists. Otherwise constrain to the destination month's final day.
This is why January 31, 2020 plus one month becomes February 29, 2020, while January 31 plus two months becomes March 31 rather than March 29.
3. Apply exact weeks, days, and clock units
Convert Weeks, Days, Hours, Minutes, and Seconds into one exact signed-second amount. One week is 604,800 seconds and one civil day is 86,400 seconds. Apply that amount to the constrained intermediate date and time.
4. Handle midnight and year rollover
Exact seconds naturally roll through the clock and calendar. For example, December 31, 2026 at 23:59:30 plus 90 seconds is January 1, 2027 at 00:01:00.
5. Respect leap years and supported range
Gregorian leap years are divisible by 4, except century years unless divisible by 400. Results outside 0001-01-01 00:00:00 through 9999-12-31 23:59:59 are rejected rather than wrapped or guessed.
Worked sequence
Start with 2021-01-31 23:30:00. Add one Month: the intermediate value is constrained to 2021-02-28 23:30:00. Add one Day and two Hours: the final result is 2021-03-02 01:30:00.
Timezone and sibling-app boundary
This method models timezone-free civil time. It does not calculate elapsed UTC time across daylight-saving transitions. Use Date Calculator for date-only work, Time Calculator for clock-only or duration arithmetic, and Time Duration Calculator to measure between two complete dated endpoints.