Add or Subtract Time from a Date

Add or subtract minutes, hours, days, weeks, months or years from any date and time. Month ends clamp correctly, so Jan 31 plus one month is Feb 29 in 2024.

The interactive tool loads here when JavaScript runs.

About this tool

What is the Date Arithmetic calculator?

Pick a base date and time, choose Add or Subtract, enter a whole number and a unit (minutes, hours, days, weeks, months or years), and click Calculate Date. The result is shown as a local date and time, an ISO 8601 UTC string and an RFC 7231-style UTC string, and the Copy button puts all of it on the clipboard.

Six presets fill the form for common jumps: Next Week, Next Month, Next Year, Yesterday, Last Week and Last Month. The arithmetic itself is done by date-fns in your browser, using your device's time zone.

  • Add or subtract minutes, hours, days, weeks, months or years
  • Month-end and leap-day clamping via date-fns
  • DST-aware: days keep the clock time, hours are elapsed time
  • Local, ISO 8601 and UTC output with one-click copy
  • Six quick presets for common jumps
Read the guide: Date Math for Developers: Month Ends, DST Days and Unix Time

Updated

How to use the Date Arithmetic calculator

  1. Choose the Base Date with the date and time picker.
  2. Set Operation to Add or Subtract.
  3. Type a whole number in Value and pick a Unit, or click a Quick Preset such as Next Month.
  4. Click Calculate Date and read the Result Date, ISO Format and UTC Format panels.
  5. Click Copy to put the base date, the operation and both result formats on the clipboard.

Worked examples

Month-end clamping

Input

2024-01-31 09:00, Add 1 Months

Output

2024-02-29 09:00

February 2024 has 29 days, so the result is clamped to the last day of the month instead of spilling into March.

Leap day plus a year

Input

2024-02-29 12:00, Add 1 Years

Output

2025-02-28 12:00

2025 has no 29 February. The same rule applies if you subtract four years from 2028-02-29 to land on another leap day: that one works exactly.

Background and insight

Adding months is not a fixed number of days, and naive code gets it wrong. JavaScript's Date.setMonth(getMonth() + 1) on 31 January produces 2 or 3 March, because it rolls the impossible 31 February forward. This tool clamps instead: 31 January 2024 plus one month is 29 February 2024, and 31 March minus one month is 29 February too. Java's java.time, Python's dateutil.relativedelta and PostgreSQL's interval arithmetic all clamp the same way.

Days and hours are different units once daylight saving time is involved. Adding one day keeps the wall-clock time, so 9 March 2024 12:00 plus one day in New York is 10 March 12:00, even though only 23 hours passed. Adding 24 hours gives 13:00 instead. Pick the unit that matches what you mean: "same time tomorrow" is days, "a 24-hour token lifetime" is hours.

Leap years follow the Gregorian rule: divisible by 4, except centuries, except centuries divisible by 400. 2000 was a leap year, 2100 will not be. Adding one year to 29 February lands on 28 February of the next year.

Common use cases

  • Deadlines and notice periods

    Work out the date 30 days, 6 weeks or 3 months after a contract or invoice date.

  • Token and certificate expiry

    Find the exact timestamp 72 hours or 90 days from issue when checking an expiry claim.

  • Test fixtures

    Generate the edge-case dates a billing or subscription test needs: month ends, leap days and DST weekends.

  • Planning schedules

    Find the date two weeks after a sprint start or a year after a launch.

Tips and limitations

  • For a date counted from today, such as 90 days or 6 weeks from today, set Base Date to today, choose Add and enter 90 days or 6 weeks.
  • Values are whole numbers. 1.5 days is truncated to 1; use 36 hours instead.
  • Results use your browser's time zone. The ISO Format line converts that local result to UTC, so it can show a different calendar day.
  • Adding one month and then subtracting one month does not always return the start date: 31 January becomes 29 February, then 29 January.
  • Values large enough to leave JavaScript's date range (about 273,000 years either side of 1970) show an error instead of a broken date.

Sources and further reading

  1. Date.prototype.setMonth(), MDN Web Docs. How JavaScript rolls an impossible date forward
  2. LocalDate (Java SE 21), Oracle. plusMonths clamps to the last valid day of the month
  3. relativedelta, dateutil. Python month and year arithmetic
  4. Date/Time Functions and Operators, PostgreSQL Global Development Group. Interval arithmetic in PostgreSQL
  5. Daylight Saving Time Rules, National Institute of Standards and Technology. When US clocks change

Frequently asked questions

What is January 31 plus one month?

It is the last day of February: 29 February in a leap year such as 2024, and 28 February otherwise. The calculator clamps to the end of the shorter month rather than rolling into March, which is what a bare JavaScript setMonth call would do.

Is adding 1 day the same as adding 24 hours?

Not on a daylight saving change. Adding a day keeps the same clock time, while adding 24 hours adds elapsed time. On the spring-forward weekend in New York, noon plus one day is noon the next day, but noon plus 24 hours is 1 PM.

What happens when I add a year to February 29?

You get 28 February of the following year, because the next year has no leap day. Adding four years from 29 February 2024 gives 29 February 2028, since 2028 is a leap year. The rule follows the Gregorian calendar used by date-fns.

Can I subtract months to find a past date?

Yes. Choose Subtract, enter the number and pick Months. The same clamping applies backwards: 31 March 2024 minus one month is 29 February 2024. The Last Month preset fills the form with Subtract, 1 and Months for you.

Which time zone does the date calculator use?

It uses your browser's time zone for the base date and the local result. The ISO Format and UTC Format lines show the same instant in UTC, so someone in another zone can read the exact moment unambiguously.

Can I add fractional values like 2.5 days?

No, the value is truncated to a whole number before it is applied, so 2.5 days becomes 2 days. Convert to a smaller unit instead: 2.5 days is 60 hours, and 1.5 hours is 90 minutes.

Is there an in-depth guide to the Date Arithmetic calculator?

Yes. “Date Math for Developers: Month Ends, DST Days and Unix Time” covers the background, how it works, common pitfalls and worked examples. Read the full guide.