Date Calculator - Add or Subtract Days
You might also like...
Need to know a specific date in the future or past? This calculator lets you quickly add or subtract any duration from a starting date.
How It Works
Simply pick your start date, choose whether you want to add or subtract time, and then enter the duration in years, months, weeks, and/or days. The calculator will instantly show you the resulting date.
Logic & Formulas
This calculator uses the `add()` and `sub()` functions from the `date-fns` library. These functions take a starting date and a duration object to return a new date.
The duration object is constructed from the user's input:
{ years, months, weeks, days }
Based on the selected operation, the calculator then calls either `add(startDate, duration)` or `sub(startDate, duration)` to compute the final date. This approach correctly handles all date complexities, such as leap years.