How Date Arithmetic Works
Date arithmetic — adding or subtracting days, months, or years from a date — is more complex than simple addition because months have different lengths and leap years alter February. The safest method for software is to convert dates to Julian Day Numbers (JDN), an integer count of days since noon on 1 January 4713 BC, perform the arithmetic on those integers, then convert back. For month/year arithmetic, the rules are: add the months first, then check if the result date is valid (e.g., adding 1 month to January 31 gives February 31, which is rounded to February 28/29).
ISO 8601 is the international standard for date representation: YYYY-MM-DD (e.g., 2024-03-15). This format sorts correctly as a string. Business date calculations often exclude weekends and public holidays, requiring a holiday calendar for the relevant country and jurisdiction.
Month Lengths Quick Reference
| Month | Days (standard) | Days (leap year) |
|---|---|---|
| January | 31 | 31 |
| February | 28 | 29 |
| March | 31 | 31 |
| April | 30 | 30 |
| May | 31 | 31 |
| June | 30 | 30 |
| July | 31 | 31 |
| August | 31 | 31 |
| September | 30 | 30 |
| October | 31 | 31 |
| November | 30 | 30 |
| December | 31 | 31 |
