Add or Subtract Dates
Date arithmetic that tells you when it clamped.
Date arithmetic that tells you when it clamped.
How to use it
- Enter the starting date. Written as YYYY-MM-DD.
- Set the amount and unit. Days, weeks, months or years, before or after.
- Read the answer. With the weekday, and a note if the day had to be clamped.
When you would use this
Adding a month to a date sounds like one operation and is really a choice between three, which most tools make for you without saying so. 31 January plus one month can be 28 February, 3 March, or an error. This clamps to the end of the month, because that is what a person means by a month later: the answer stays in the month they named. Rolling over to 3 March puts you in the wrong month, which is worse. Clamping has an honest cost. It is not reversible, so adding a month and taking one back leaves you on the 28th, and repeated addition drifts: one month added twelve times from 31 January lands on 28 January rather than the 31st. There is no version of this arithmetic without a trade off, so rather than hide it the tool tells you when a clamp happened and why. Days and weeks have none of this ambiguity and are exact. Leap years are handled properly, century rule included, so 1900 has 28 days in February and 2000 has 29.
Questions
- What is 31 January plus one month?
- 28 February here, because the answer stays in the month you named. The other defensible answer is 3 March, which is what rolling over gives, and it puts you in the wrong month entirely. The tool says when it clamped so the choice is visible rather than silent.
- Why does adding a month and then subtracting one not return me to the start?
- Because clamping is not reversible. 31 January plus a month is 28 February, and 28 February minus a month is 28 January. That is a genuine cost of clamping rather than a bug, and it is the reason the tool tells you when a clamp happened.
- How are leap years handled?
- Correctly, including the century rule: 1900 was not a leap year and 2000 was. 29 February plus one year clamps to 28 February, and plus four years lands back on the 29th.